@mobil80-dev/chatbot-widget 1.0.7 β†’ 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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/index.js +102 -39
  3. package/package.json +5 -2
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- VaultChat JS
1
+ ## πŸ€–Chatbot
2
2
 
3
- VaultChat is a lightweight JavaScript chat widget that can be embedded into any website without iframes or frameworks.
3
+ A lightweight JavaScript chatbot widget powered by VaultChat, designed to be embedded into any website without iframes or frameworks.
4
4
 
5
5
  ## ✨ Features
6
6
 
@@ -30,7 +30,7 @@ npm install @mobil80-dev/chatbot-widget
30
30
  ```
31
31
 
32
32
  ## 🧩 Vue
33
- ## πŸš€ Usage (Vue 3)
33
+ ### πŸš€ Usage (Vue 3)
34
34
  ```
35
35
  import { onMounted } from 'vue'
36
36
  import VaultChat from '@mobil80-dev/chatbot-widget'
package/index.js CHANGED
@@ -1,12 +1,63 @@
1
1
  const VaultChat = {
2
- init (config) {
3
- // if (!config || !config.apiKey) {
4
- // console.error('VaultChat: apiKey is required')
5
- // return
6
- // }
7
-
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
+ ============================ */
8
45
  const button = document.createElement('div')
9
- button.innerHTML = 'πŸ’¬'
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
+ }
10
61
 
11
62
  Object.assign(button.style, {
12
63
  position: 'fixed',
@@ -15,48 +66,44 @@ const VaultChat = {
15
66
  width: '56px',
16
67
  height: '56px',
17
68
  borderRadius: '50%',
18
- background: config.primaryColor || '#2563eb',
69
+ background: primaryColor,
19
70
  color: '#fff',
20
71
  display: 'flex',
21
72
  alignItems: 'center',
22
73
  justifyContent: 'center',
23
74
  cursor: 'pointer',
24
75
  fontSize: '24px',
25
- zIndex: 9999
76
+ zIndex: 999999
26
77
  })
27
78
 
79
+ /* ============================
80
+ CHAT CARD
81
+ ============================ */
28
82
  const card = document.createElement('div')
83
+
29
84
  card.innerHTML = `
30
-
31
- <div style="padding:12px;font-weight:bold;border-bottom:1px solid #eee">
32
- <div style="
33
- text-align:left;
34
- font-size:14px;
35
- color:#94a3b8;
36
- padding-bottom:6px;
37
- user-select:none;
38
- opacity:0.8">
39
- Powered by <strong>VaultChat</strong>
40
- </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>
41
92
  </div>
42
-
43
93
 
44
94
  <div id="vc-messages" style="
45
95
  flex:1;
46
96
  padding:12px;
47
97
  overflow-y:auto;
48
- background:#f8fafc">
49
- <div style="
50
- background:#e5e7eb;
51
- padding:8px 12px;
52
- border-radius:12px;
53
- max-width:80%;
54
- margin-bottom:8px">
55
- Hi! How can I help you?
56
- </div>
98
+ background:${colors.messagesBg};
99
+ color:${colors.text}">
57
100
  </div>
58
101
 
59
- <div style="display:flex;padding:10px;border-top:1px solid #eee">
102
+ <div style="
103
+ display:flex;
104
+ padding:10px;
105
+ border-top:1px solid ${colors.headerBorder};
106
+ background:${colors.cardBg}">
60
107
  <input
61
108
  id="vc-input"
62
109
  placeholder="Type your message..."
@@ -64,14 +111,17 @@ const VaultChat = {
64
111
  flex:1;
65
112
  padding:10px;
66
113
  border-radius:8px;
67
- border:1px solid #ccc"
114
+ border:1px solid ${colors.inputBorder};
115
+ background:${colors.inputBg};
116
+ color:${colors.text};
117
+ outline:none"
68
118
  />
69
119
  <button id="vc-send" style="
70
120
  margin-left:8px;
71
121
  padding:0 14px;
72
122
  border:none;
73
123
  border-radius:8px;
74
- background:${config.primaryColor || '#2563eb'};
124
+ background:${primaryColor};
75
125
  color:white;
76
126
  cursor:pointer">
77
127
  ➀
@@ -85,10 +135,10 @@ const VaultChat = {
85
135
  right: '20px',
86
136
  width: '400px',
87
137
  height: '420px',
88
- background: '#fff',
138
+ background: colors.cardBg,
89
139
  borderRadius: '12px',
90
140
  boxShadow: '0 10px 30px rgba(0,0,0,.3)',
91
- zIndex: 9999,
141
+ zIndex: 999999,
92
142
  display: 'none',
93
143
  flexDirection: 'column'
94
144
  })
@@ -102,6 +152,9 @@ const VaultChat = {
102
152
  document.body.appendChild(button)
103
153
  document.body.appendChild(card)
104
154
 
155
+ /* ============================
156
+ CHAT LOGIC
157
+ ============================ */
105
158
  const messages = card.querySelector('#vc-messages')
106
159
  const input = card.querySelector('#vc-input')
107
160
  const sendBtn = card.querySelector('#vc-send')
@@ -109,8 +162,8 @@ const VaultChat = {
109
162
  function addUserMessage (text) {
110
163
  const div = document.createElement('div')
111
164
  div.style.cssText = `
112
- background:${config.primaryColor || '#2563eb'};
113
- color:white;
165
+ background:${primaryColor};
166
+ color:${colors.userText};
114
167
  padding:8px 12px;
115
168
  border-radius:12px;
116
169
  max-width:80%;
@@ -123,7 +176,8 @@ const VaultChat = {
123
176
  function addBotMessage (text) {
124
177
  const div = document.createElement('div')
125
178
  div.style.cssText = `
126
- background:#e5e7eb;
179
+ background:${colors.botBubble};
180
+ color:${colors.text};
127
181
  padding:8px 12px;
128
182
  border-radius:12px;
129
183
  max-width:80%;
@@ -140,6 +194,14 @@ const VaultChat = {
140
194
  addUserMessage(text)
141
195
  input.value = ''
142
196
 
197
+ // πŸ” API key missing β†’ internal response only
198
+ if (!config.apiKey) {
199
+ addBotMessage(
200
+ '⚠️ API key not configured. Please add apiKey in VaultChat.init().'
201
+ )
202
+ return
203
+ }
204
+
143
205
  try {
144
206
  const res = await fetch('https://api.vaultchat.io/askChatbot', {
145
207
  method: 'POST',
@@ -152,7 +214,8 @@ const VaultChat = {
152
214
 
153
215
  const data = await res.json()
154
216
  const reply =
155
- data?.data?.blocks?.map(b => b.text).join('\n') || 'No response'
217
+ data?.data?.blocks?.map(b => b.text).join('\n') ||
218
+ 'No response received'
156
219
 
157
220
  addBotMessage(reply)
158
221
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mobil80-dev/chatbot-widget",
3
- "version": "1.0.7",
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
  }