@locdo.tech/botiq-chat-sdk 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BotIQ (LocDo.Tech)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # @locdo.tech/botiq-chat-sdk
2
+
3
+ Embed the **BotIQ** AI chatbot widget into any website with one line of code. Vanilla JS, React, and Vue entry points included.
4
+
5
+ > Live dashboard & docs: [botiq.vn](https://botiq.vn)
6
+
7
+ ---
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @locdo.tech/botiq-chat-sdk
13
+ ```
14
+
15
+ You also need a **Widget Embed Key** (`sk-biq-...`) issued from your BotIQ admin dashboard.
16
+
17
+ ---
18
+
19
+ ## Quick start — Vanilla JS / TS
20
+
21
+ ```ts
22
+ import { init } from '@locdo.tech/botiq-chat-sdk';
23
+
24
+ const dispose = init({
25
+ apiKey: 'sk-biq-xxxxxxxxxxxxxxxx',
26
+ apiUrl: 'https://api.botiq.vn',
27
+ botName: 'SpaBot',
28
+ position: 'bottom-right',
29
+ primaryColor: '#F97316',
30
+ });
31
+
32
+ // Later, to remove the widget:
33
+ dispose();
34
+ ```
35
+
36
+ `init()` returns a cleanup function — call it to unmount the widget.
37
+
38
+ ---
39
+
40
+ ## React
41
+
42
+ ```tsx
43
+ import { BotIQWidget } from '@locdo.tech/botiq-chat-sdk/react';
44
+
45
+ export function App() {
46
+ return (
47
+ <BotIQWidget
48
+ apiKey="sk-biq-xxxxxxxxxxxxxxxx"
49
+ apiUrl="https://api.botiq.vn"
50
+ botName="SpaBot"
51
+ position="bottom-right"
52
+ primaryColor="#F97316"
53
+ />
54
+ );
55
+ }
56
+ ```
57
+
58
+ > The widget reinitialises only when `apiKey` changes. To apply other prop changes, unmount and remount the component.
59
+
60
+ ---
61
+
62
+ ## Vue 3
63
+
64
+ ```vue
65
+ <script setup lang="ts">
66
+ import { BotIQWidget } from '@locdo.tech/botiq-chat-sdk/vue';
67
+ </script>
68
+
69
+ <template>
70
+ <BotIQWidget
71
+ api-key="sk-biq-xxxxxxxxxxxxxxxx"
72
+ api-url="https://api.botiq.vn"
73
+ bot-name="SpaBot"
74
+ position="bottom-right"
75
+ primary-color="#F97316"
76
+ />
77
+ </template>
78
+ ```
79
+
80
+ ---
81
+
82
+ ## Configuration
83
+
84
+ | Prop | Type | Required | Default |
85
+ |---|---|---|---|
86
+ | `apiKey` | `string` | ✅ | — |
87
+ | `apiUrl` | `string` | ✅ | — |
88
+ | `botName` | `string` | ✅ | — |
89
+ | `position` | `'bottom-right' \| 'bottom-left'` | — | `'bottom-right'` |
90
+ | `primaryColor` | `string` (hex) | — | `'#F97316'` |
91
+
92
+ The full visual design (colors, layout, greeting message) is **server-driven** via the `/widget/design` endpoint — admin/tenant pick a preset in the BotIQ dashboard and the widget fetches it on init.
93
+
94
+ ---
95
+
96
+ ## Need just a `<script>` tag?
97
+
98
+ For static HTML (no bundler), use the CDN build:
99
+
100
+ ```html
101
+ <script
102
+ src="https://bot-q-frontend.vercel.app/widget.js"
103
+ data-api-key="sk-biq-xxxxxxxxxxxxxxxx"
104
+ data-api-url="https://api.botiq.vn"
105
+ data-bot-name="SpaBot"
106
+ data-position="bottom-right"
107
+ ></script>
108
+ ```
109
+
110
+ The script auto-initialises on `DOMContentLoaded` — no JavaScript required.
111
+
112
+ ---
113
+
114
+ ## Security
115
+
116
+ The Widget Embed Key (`sk-biq-...`) is **safe to expose** in HTML/source. Each key is locked to a domain whitelist on the backend — requests from unlisted origins are rejected. To rotate or revoke a key, use the BotIQ admin dashboard.
117
+
118
+ ---
119
+
120
+ ## License
121
+
122
+ MIT © [BotIQ (LocDo.Tech)](https://botiq.vn)
@@ -0,0 +1,3 @@
1
+ import { BotIQConfig } from '../../core/config.ts';
2
+ export type { BotIQConfig };
3
+ export declare function init(userConfig: BotIQConfig): () => void;
@@ -0,0 +1,2 @@
1
+ import { t as e } from "./npm-Dbo9SB2H.js";
2
+ export { e as init };
@@ -0,0 +1,553 @@
1
+ //#region src/core/config.ts
2
+ var e = {
3
+ colors: {
4
+ primary: "#F97316",
5
+ header: "#F97316",
6
+ userBubble: "#F97316",
7
+ botBubble: "#1A1A1A",
8
+ background: "#000000",
9
+ text: "#FFFFFF"
10
+ },
11
+ layout: {
12
+ position: "bottom-right",
13
+ buttonShape: "circle",
14
+ width: 360,
15
+ height: 520
16
+ },
17
+ content: {
18
+ greeting: "Xin chào! Tôi có thể giúp gì cho bạn?",
19
+ suggestionChips: [],
20
+ placeholder: "Nhắn tin..."
21
+ },
22
+ font: "inter"
23
+ }, t = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;
24
+ function n(e) {
25
+ let n = e.primaryColor ?? "";
26
+ return {
27
+ apiKey: e.apiKey,
28
+ apiUrl: (e.apiUrl ?? "https://api.botiq.vn").replace(/\/$/, ""),
29
+ botName: e.botName ?? "BotIQ",
30
+ position: e.position === "bottom-left" ? "bottom-left" : "bottom-right",
31
+ primaryColor: t.test(n) ? n : "#F97316"
32
+ };
33
+ }
34
+ //#endregion
35
+ //#region src/core/session.ts
36
+ var r = "botiq:sessionId", i = "botiq:history:", a = 10;
37
+ function o() {
38
+ try {
39
+ let e = localStorage.getItem(r);
40
+ return e || (e = crypto.randomUUID(), localStorage.setItem(r, e)), e;
41
+ } catch {
42
+ return crypto.randomUUID();
43
+ }
44
+ }
45
+ function s(e) {
46
+ try {
47
+ let t = localStorage.getItem(i + e);
48
+ return t ? JSON.parse(t) : [];
49
+ } catch {
50
+ return [];
51
+ }
52
+ }
53
+ function c(e, t) {
54
+ try {
55
+ let n = [...s(e), ...t].slice(-a);
56
+ localStorage.setItem(i + e, JSON.stringify(n));
57
+ } catch {}
58
+ }
59
+ //#endregion
60
+ //#region src/core/api.ts
61
+ var l = {
62
+ 401: "API key không hợp lệ.",
63
+ 403: "Widget không được phép trên trang này.",
64
+ 429: "Bot đã đạt giới hạn tin nhắn tháng này."
65
+ };
66
+ async function u(e, t, n, r, i) {
67
+ try {
68
+ let a = await fetch(`${e}/widget/chat`, {
69
+ method: "POST",
70
+ headers: {
71
+ "Content-Type": "application/json",
72
+ "X-Api-Key": t
73
+ },
74
+ body: JSON.stringify({
75
+ sessionId: n,
76
+ message: r,
77
+ history: i
78
+ })
79
+ });
80
+ return a.ok ? (await a.json()).reply || "Không có phản hồi từ bot." : l[a.status] ?? "Đang gặp sự cố kỹ thuật, vui lòng liên hệ trực tiếp.";
81
+ } catch {
82
+ return "Xin lỗi, không thể kết nối. Vui lòng thử lại.";
83
+ }
84
+ }
85
+ //#endregion
86
+ //#region src/core/state.ts
87
+ var d = {
88
+ messages: [],
89
+ isLoading: !1,
90
+ isOpen: !1
91
+ }, f = /* @__PURE__ */ new Set();
92
+ function p() {
93
+ return d;
94
+ }
95
+ function m(e) {
96
+ Object.assign(d, e);
97
+ let t = {
98
+ ...d,
99
+ messages: [...d.messages]
100
+ };
101
+ f.forEach((e) => e(t));
102
+ }
103
+ function h(e) {
104
+ return f.add(e), () => f.delete(e);
105
+ }
106
+ //#endregion
107
+ //#region src/core/styles.ts
108
+ var g = {
109
+ inter: {
110
+ url: "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap",
111
+ family: "'Inter', system-ui, -apple-system, sans-serif"
112
+ },
113
+ "plus-jakarta": {
114
+ url: "https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600&display=swap",
115
+ family: "'Plus Jakarta Sans', system-ui, -apple-system, sans-serif"
116
+ },
117
+ poppins: {
118
+ url: "https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap",
119
+ family: "'Poppins', system-ui, -apple-system, sans-serif"
120
+ }
121
+ };
122
+ function _(e) {
123
+ let { colors: t, layout: n, font: r } = e, i = g[r] ?? g.inter, a = n.buttonShape === "square" ? "14px" : "50%", o = n.position === "bottom-left" ? "right: auto; left: 24px;" : "right: 24px;", s = n.position === "bottom-left" ? "bottom left" : "bottom right", c = n.position === "bottom-left" ? "right: auto; left: 0;" : "right: 0;";
124
+ return `
125
+ @import url('${i.url}');
126
+
127
+ :host {
128
+ position: fixed;
129
+ bottom: 24px;
130
+ ${o}
131
+ z-index: 2147483647;
132
+ display: block;
133
+ font-family: ${i.family};
134
+ --color-primary: ${t.primary};
135
+ --color-header: ${t.header};
136
+ --color-user: ${t.userBubble};
137
+ --color-bot: ${t.botBubble};
138
+ --color-bg: ${t.background};
139
+ --color-text: ${t.text};
140
+ --gray-50: #1A1A1A;
141
+ --gray-100: #222222;
142
+ --gray-200: #2D2D2D;
143
+ --gray-400: #9CA3AF;
144
+ --shadow-sm: 0 2px 8px rgba(0,0,0,.4);
145
+ --shadow-md: 0 8px 32px rgba(0,0,0,.5);
146
+ --shadow-lg: 0 16px 48px rgba(0,0,0,.6);
147
+ --radius-bubble: ${a};
148
+ --radius-msg: 18px;
149
+ --chat-w: ${n.width}px;
150
+ --chat-h: ${n.height}px;
151
+ }
152
+
153
+ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
154
+
155
+ /* ── Bubble ─────────────────────────────── */
156
+ .bubble {
157
+ width: 56px;
158
+ height: 56px;
159
+ border-radius: var(--radius-bubble);
160
+ background: var(--color-primary);
161
+ border: none;
162
+ cursor: pointer;
163
+ display: flex;
164
+ align-items: center;
165
+ justify-content: center;
166
+ box-shadow: var(--shadow-md);
167
+ transition: transform .2s ease, box-shadow .2s ease;
168
+ outline: none;
169
+ }
170
+
171
+ .bubble:hover { transform: scale(1.08); box-shadow: var(--shadow-lg); }
172
+ .bubble:active { transform: scale(0.96); }
173
+
174
+ .bubble svg { width: 26px; height: 26px; fill: #fff; transition: opacity .15s; }
175
+ .bubble .icon-chat { opacity: 1; }
176
+ .bubble .icon-close { opacity: 0; position: absolute; }
177
+ .bubble.open .icon-chat { opacity: 0; }
178
+ .bubble.open .icon-close { opacity: 1; }
179
+
180
+ /* ── Chat Window ────────────────────────── */
181
+ .chat-window {
182
+ position: absolute;
183
+ bottom: 72px;
184
+ ${c}
185
+ width: var(--chat-w);
186
+ height: var(--chat-h);
187
+ background: var(--color-bg);
188
+ border-radius: 20px;
189
+ box-shadow: var(--shadow-lg);
190
+ display: flex;
191
+ flex-direction: column;
192
+ overflow: hidden;
193
+ transform-origin: ${s};
194
+ transform: scale(.94) translateY(8px);
195
+ opacity: 0;
196
+ pointer-events: none;
197
+ transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .18s ease;
198
+ }
199
+
200
+ .chat-window.open { transform: scale(1) translateY(0); opacity: 1; pointer-events: all; }
201
+
202
+ /* ── Header ─────────────────────────────── */
203
+ .chat-header {
204
+ background: var(--color-header);
205
+ padding: 16px 16px 14px;
206
+ display: flex;
207
+ align-items: center;
208
+ gap: 10px;
209
+ flex-shrink: 0;
210
+ }
211
+
212
+ .avatar {
213
+ width: 36px;
214
+ height: 36px;
215
+ border-radius: 50%;
216
+ background: rgba(255,255,255,.2);
217
+ display: flex;
218
+ align-items: center;
219
+ justify-content: center;
220
+ flex-shrink: 0;
221
+ }
222
+
223
+ .avatar svg { width: 20px; height: 20px; fill: #fff; }
224
+
225
+ .header-text { flex: 1; min-width: 0; }
226
+
227
+ .bot-name {
228
+ color: #fff;
229
+ font-weight: 600;
230
+ font-size: 15px;
231
+ line-height: 1.2;
232
+ display: block;
233
+ white-space: nowrap;
234
+ overflow: hidden;
235
+ text-overflow: ellipsis;
236
+ }
237
+
238
+ .bot-status { color: rgba(255,255,255,.75); font-size: 12px; display: block; margin-top: 1px; }
239
+
240
+ .close-btn {
241
+ width: 30px;
242
+ height: 30px;
243
+ border-radius: 50%;
244
+ background: rgba(255,255,255,.15);
245
+ border: none;
246
+ cursor: pointer;
247
+ color: #fff;
248
+ font-size: 18px;
249
+ display: flex;
250
+ align-items: center;
251
+ justify-content: center;
252
+ flex-shrink: 0;
253
+ transition: background .15s;
254
+ }
255
+ .close-btn:hover { background: rgba(255,255,255,.25); }
256
+
257
+ /* ── Messages ───────────────────────────── */
258
+ .messages {
259
+ flex: 1;
260
+ overflow-y: auto;
261
+ padding: 16px 14px;
262
+ display: flex;
263
+ flex-direction: column;
264
+ gap: 10px;
265
+ scroll-behavior: smooth;
266
+ }
267
+
268
+ .messages::-webkit-scrollbar { width: 4px; }
269
+ .messages::-webkit-scrollbar-track { background: transparent; }
270
+ .messages::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 2px; }
271
+
272
+ .message { display: flex; flex-direction: column; max-width: 82%; }
273
+ .message.user { align-self: flex-end; align-items: flex-end; }
274
+ .message.assistant { align-self: flex-start; align-items: flex-start; }
275
+
276
+ .message-bubble {
277
+ padding: 10px 14px;
278
+ border-radius: var(--radius-msg);
279
+ font-size: 14px;
280
+ line-height: 1.5;
281
+ white-space: pre-wrap;
282
+ word-break: break-word;
283
+ }
284
+
285
+ .message.user .message-bubble {
286
+ background: var(--color-user);
287
+ color: #fff;
288
+ border-bottom-right-radius: 4px;
289
+ }
290
+
291
+ .message.assistant .message-bubble {
292
+ background: var(--color-bot);
293
+ color: var(--color-text);
294
+ border-bottom-left-radius: 4px;
295
+ }
296
+
297
+ /* ── Typing Indicator ───────────────────── */
298
+ .typing {
299
+ display: flex;
300
+ align-items: center;
301
+ gap: 4px;
302
+ padding: 12px 14px;
303
+ background: var(--color-bot);
304
+ border-radius: var(--radius-msg);
305
+ border-bottom-left-radius: 4px;
306
+ align-self: flex-start;
307
+ width: fit-content;
308
+ }
309
+
310
+ .typing span {
311
+ width: 7px;
312
+ height: 7px;
313
+ border-radius: 50%;
314
+ background: var(--color-primary);
315
+ opacity: 0.5;
316
+ animation: bounce 1.2s infinite ease-in-out;
317
+ }
318
+
319
+ .typing span:nth-child(2) { animation-delay: .2s; }
320
+ .typing span:nth-child(3) { animation-delay: .4s; }
321
+
322
+ @keyframes bounce {
323
+ 0%, 60%, 100% { transform: translateY(0); }
324
+ 30% { transform: translateY(-6px); }
325
+ }
326
+
327
+ /* ── Empty / Greeting State ─────────────── */
328
+ .empty-state {
329
+ flex: 1;
330
+ display: flex;
331
+ flex-direction: column;
332
+ align-items: center;
333
+ justify-content: center;
334
+ gap: 8px;
335
+ color: var(--gray-400);
336
+ font-size: 13px;
337
+ text-align: center;
338
+ padding: 24px;
339
+ }
340
+
341
+ .empty-state svg { width: 40px; height: 40px; fill: var(--gray-200); margin-bottom: 4px; }
342
+ .empty-state .greeting { color: var(--color-text); font-size: 13px; opacity: 0.7; }
343
+
344
+ /* ── Suggestion Chips ───────────────────── */
345
+ .chips {
346
+ display: flex;
347
+ flex-wrap: wrap;
348
+ gap: 6px;
349
+ justify-content: center;
350
+ margin-top: 4px;
351
+ }
352
+
353
+ .chip {
354
+ padding: 5px 12px;
355
+ border-radius: 16px;
356
+ border: 1.5px solid var(--color-primary);
357
+ color: var(--color-primary);
358
+ background: transparent;
359
+ font-size: 12px;
360
+ font-family: inherit;
361
+ cursor: pointer;
362
+ transition: background .15s, color .15s;
363
+ }
364
+
365
+ .chip:hover {
366
+ background: var(--color-primary);
367
+ color: #fff;
368
+ }
369
+
370
+ /* ── Footer / Input ─────────────────────── */
371
+ .chat-footer {
372
+ border-top: 1px solid var(--gray-100);
373
+ padding: 10px 12px;
374
+ background: var(--color-bg);
375
+ flex-shrink: 0;
376
+ }
377
+
378
+ .input-row { display: flex; align-items: flex-end; gap: 8px; }
379
+
380
+ .input {
381
+ flex: 1;
382
+ min-height: 38px;
383
+ max-height: 100px;
384
+ border: 1.5px solid var(--gray-200);
385
+ border-radius: 12px;
386
+ padding: 9px 12px;
387
+ font-family: inherit;
388
+ font-size: 14px;
389
+ color: var(--color-text);
390
+ resize: none;
391
+ outline: none;
392
+ background: var(--gray-50);
393
+ line-height: 1.4;
394
+ overflow-y: auto;
395
+ transition: border-color .15s;
396
+ }
397
+
398
+ .input:focus { border-color: var(--color-primary); background: var(--gray-100); }
399
+ .input::placeholder { color: var(--gray-400); }
400
+
401
+ .send-btn {
402
+ width: 38px;
403
+ height: 38px;
404
+ border-radius: 10px;
405
+ background: var(--color-primary);
406
+ border: none;
407
+ cursor: pointer;
408
+ display: flex;
409
+ align-items: center;
410
+ justify-content: center;
411
+ flex-shrink: 0;
412
+ transition: filter .15s, transform .1s;
413
+ }
414
+
415
+ .send-btn:hover { filter: brightness(0.88); }
416
+ .send-btn:active { transform: scale(0.94); }
417
+ .send-btn:disabled { background: var(--gray-200); cursor: not-allowed; filter: none; }
418
+ .send-btn svg { width: 18px; height: 18px; fill: #fff; }
419
+ `;
420
+ }
421
+ //#endregion
422
+ //#region src/core/ui.ts
423
+ var v = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 2H4a2 2 0 00-2 2v18l4-4h14a2 2 0 002-2V4a2 2 0 00-2-2z\"/>\n</svg>", y = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z\"/>\n</svg>", b = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M12 2a2 2 0 012 2c0 .74-.4 1.38-1 1.72V7h3a3 3 0 013 3v8a3 3 0 01-3 3H8a3 3 0 01-3-3v-8a3 3 0 013-3h3V5.72A2 2 0 0110 4a2 2 0 012-2zm-2 9a1.5 1.5 0 100 3 1.5 1.5 0 000-3zm4 0a1.5 1.5 0 100 3 1.5 1.5 0 000-3z\"/>\n</svg>", x = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z\"/>\n</svg>", S = "<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 2H4a2 2 0 00-2 2v18l4-4h14a2 2 0 002-2V4a2 2 0 00-2-2zm-2 10H6v-2h12v2zm0-3H6V7h12v2z\"/>\n</svg>";
424
+ function C(e) {
425
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
426
+ }
427
+ function w(e, t, n, r) {
428
+ let i, a, o, s, c, l, { content: u } = t;
429
+ function d(n) {
430
+ n.setAttribute("data-position", t.layout.position), i = n.attachShadow({ mode: "open" });
431
+ let d = document.createElement("style");
432
+ d.textContent = _(t), i.appendChild(d), a = document.createElement("button"), a.className = "bubble", a.setAttribute("aria-label", `Open ${e.botName} chat`), a.innerHTML = `
433
+ <span class="icon-chat">${v}</span>
434
+ <span class="icon-close">${y}</span>
435
+ `, a.addEventListener("click", r), i.appendChild(a), o = document.createElement("div"), o.className = "chat-window", o.setAttribute("role", "dialog"), o.setAttribute("aria-label", `${e.botName} chat`), o.innerHTML = `
436
+ <div class="chat-header">
437
+ <div class="avatar">${b}</div>
438
+ <div class="header-text">
439
+ <span class="bot-name">${C(e.botName)}</span>
440
+ <span class="bot-status">Trực tuyến</span>
441
+ </div>
442
+ <button class="close-btn" aria-label="Close chat">×</button>
443
+ </div>
444
+ <div class="messages" id="messages-container"></div>
445
+ <div class="chat-footer">
446
+ <div class="input-row">
447
+ <textarea
448
+ class="input"
449
+ placeholder="${C(u.placeholder)}"
450
+ rows="1"
451
+ maxlength="2000"
452
+ aria-label="Message input"
453
+ ></textarea>
454
+ <button class="send-btn" aria-label="Send message">
455
+ ${x}
456
+ </button>
457
+ </div>
458
+ </div>
459
+ `, o.querySelector(".close-btn").addEventListener("click", r), s = o.querySelector("#messages-container"), c = o.querySelector(".input"), l = o.querySelector(".send-btn"), c.addEventListener("input", () => {
460
+ c.style.height = "auto", c.style.height = Math.min(c.scrollHeight, 100) + "px";
461
+ }), c.addEventListener("keydown", (e) => {
462
+ e.key === "Enter" && !e.shiftKey && (e.preventDefault(), f());
463
+ }), l.addEventListener("click", f), i.appendChild(o);
464
+ }
465
+ function f() {
466
+ let e = c.value.trim();
467
+ !e || l.disabled || (c.value = "", c.style.height = "auto", n(e));
468
+ }
469
+ function p(e) {
470
+ if (e.messages.length === 0 && !e.isLoading) {
471
+ let e = u.suggestionChips.length > 0 ? `<div class="chips">${u.suggestionChips.map((e) => `<button class="chip">${C(e)}</button>`).join("")}</div>` : "";
472
+ s.innerHTML = `
473
+ <div class="empty-state">
474
+ ${S}
475
+ <span class="greeting">${C(u.greeting)}</span>
476
+ ${e}
477
+ </div>
478
+ `, s.querySelectorAll(".chip").forEach((e) => {
479
+ e.addEventListener("click", () => n(e.textContent ?? ""));
480
+ });
481
+ return;
482
+ }
483
+ let t = e.messages.map((e) => `
484
+ <div class="message ${e.role}">
485
+ <div class="message-bubble">${C(e.content)}</div>
486
+ </div>
487
+ `).join(""), r = e.isLoading ? "<div class=\"typing\"><span></span><span></span><span></span></div>" : "";
488
+ s.innerHTML = t + r, s.scrollTop = s.scrollHeight;
489
+ }
490
+ function m(t) {
491
+ t.isOpen ? (o.classList.add("open"), a.classList.add("open"), a.setAttribute("aria-label", `Close ${e.botName} chat`), requestAnimationFrame(() => c.focus())) : (o.classList.remove("open"), a.classList.remove("open"), a.setAttribute("aria-label", `Open ${e.botName} chat`)), l.disabled = t.isLoading, p(t);
492
+ }
493
+ return {
494
+ mount: d,
495
+ update: m
496
+ };
497
+ }
498
+ //#endregion
499
+ //#region src/builds/npm/index.ts
500
+ function T(t) {
501
+ if (!t.apiKey) return console.warn("[BotIQ] apiKey is required"), () => void 0;
502
+ let r = n(t), i = {
503
+ ...e,
504
+ colors: {
505
+ ...e.colors,
506
+ primary: r.primaryColor,
507
+ header: r.primaryColor,
508
+ userBubble: r.primaryColor
509
+ },
510
+ layout: {
511
+ ...e.layout,
512
+ position: r.position
513
+ }
514
+ }, a = o();
515
+ m({ messages: s(a) });
516
+ let l = document.createElement("div");
517
+ document.body.appendChild(l);
518
+ let d = w(r, i, g, _);
519
+ d.mount(l);
520
+ let f = h((e) => d.update(e));
521
+ d.update(p());
522
+ function g(e) {
523
+ let t = p();
524
+ if (t.isLoading) return;
525
+ let n = {
526
+ role: "user",
527
+ content: e
528
+ };
529
+ m({
530
+ messages: [...t.messages, n],
531
+ isLoading: !0
532
+ }), u(r.apiUrl, r.apiKey, a, e, t.messages).then((e) => {
533
+ let t = {
534
+ role: "assistant",
535
+ content: e
536
+ };
537
+ m({
538
+ messages: [...p().messages, t],
539
+ isLoading: !1
540
+ }), c(a, [n, t]);
541
+ }).catch(() => {
542
+ m({ isLoading: !1 });
543
+ });
544
+ }
545
+ function _() {
546
+ m({ isOpen: !p().isOpen });
547
+ }
548
+ return () => {
549
+ f(), l.remove();
550
+ };
551
+ }
552
+ //#endregion
553
+ export { T as t };
@@ -0,0 +1,2 @@
1
+ import { BotIQConfig } from './index.ts';
2
+ export declare function BotIQWidget(props: BotIQConfig): null;
@@ -0,0 +1,8 @@
1
+ import { t as e } from "./npm-Dbo9SB2H.js";
2
+ import { useEffect as t } from "react";
3
+ //#region src/builds/npm/react.tsx
4
+ function n(n) {
5
+ return t(() => e(n), [n.apiKey]), null;
6
+ }
7
+ //#endregion
8
+ export { n as BotIQWidget };
@@ -0,0 +1,50 @@
1
+ import { PropType } from 'vue';
2
+ import { BotIQConfig } from './index.ts';
3
+ export declare const BotIQWidget: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
4
+ apiKey: {
5
+ type: StringConstructor;
6
+ required: true;
7
+ };
8
+ apiUrl: {
9
+ type: StringConstructor;
10
+ default: undefined;
11
+ };
12
+ botName: {
13
+ type: StringConstructor;
14
+ default: undefined;
15
+ };
16
+ position: {
17
+ type: PropType<BotIQConfig["position"]>;
18
+ default: undefined;
19
+ };
20
+ primaryColor: {
21
+ type: StringConstructor;
22
+ default: undefined;
23
+ };
24
+ }>, () => null, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
25
+ apiKey: {
26
+ type: StringConstructor;
27
+ required: true;
28
+ };
29
+ apiUrl: {
30
+ type: StringConstructor;
31
+ default: undefined;
32
+ };
33
+ botName: {
34
+ type: StringConstructor;
35
+ default: undefined;
36
+ };
37
+ position: {
38
+ type: PropType<BotIQConfig["position"]>;
39
+ default: undefined;
40
+ };
41
+ primaryColor: {
42
+ type: StringConstructor;
43
+ default: undefined;
44
+ };
45
+ }>> & Readonly<{}>, {
46
+ primaryColor: string;
47
+ apiUrl: string;
48
+ botName: string;
49
+ position: "bottom-right" | "bottom-left" | undefined;
50
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
@@ -0,0 +1,44 @@
1
+ import { t as e } from "./npm-Dbo9SB2H.js";
2
+ import { defineComponent as t, onMounted as n, onUnmounted as r } from "vue";
3
+ //#region src/builds/npm/vue.ts
4
+ var i = t({
5
+ name: "BotIQWidget",
6
+ props: {
7
+ apiKey: {
8
+ type: String,
9
+ required: !0
10
+ },
11
+ apiUrl: {
12
+ type: String,
13
+ default: void 0
14
+ },
15
+ botName: {
16
+ type: String,
17
+ default: void 0
18
+ },
19
+ position: {
20
+ type: String,
21
+ default: void 0
22
+ },
23
+ primaryColor: {
24
+ type: String,
25
+ default: void 0
26
+ }
27
+ },
28
+ setup(t) {
29
+ let i;
30
+ return n(() => {
31
+ i = e({
32
+ apiKey: t.apiKey,
33
+ apiUrl: t.apiUrl,
34
+ botName: t.botName,
35
+ position: t.position,
36
+ primaryColor: t.primaryColor
37
+ });
38
+ }), r(() => {
39
+ i?.();
40
+ }), () => null;
41
+ }
42
+ });
43
+ //#endregion
44
+ export { i as BotIQWidget };
package/package.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "@locdo.tech/botiq-chat-sdk",
3
+ "version": "0.1.0",
4
+ "description": "BotIQ chat widget SDK — embed AI chatbot into any website with vanilla JS, React, or Vue.",
5
+ "keywords": [
6
+ "botiq",
7
+ "chatbot",
8
+ "ai",
9
+ "widget",
10
+ "react",
11
+ "vue",
12
+ "customer-support"
13
+ ],
14
+ "license": "MIT",
15
+ "author": "BotIQ (LocDo.Tech)",
16
+ "homepage": "https://botiq.vn",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/locdo-tech/botiq.git",
20
+ "directory": "apps/widget"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/locdo-tech/botiq/issues"
24
+ },
25
+ "type": "module",
26
+ "main": "./dist/sdk/index.js",
27
+ "module": "./dist/sdk/index.js",
28
+ "types": "./dist/sdk/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "import": "./dist/sdk/index.js",
32
+ "types": "./dist/sdk/index.d.ts"
33
+ },
34
+ "./react": {
35
+ "import": "./dist/sdk/react.js",
36
+ "types": "./dist/sdk/react.d.ts"
37
+ },
38
+ "./vue": {
39
+ "import": "./dist/sdk/vue.js",
40
+ "types": "./dist/sdk/vue.d.ts"
41
+ }
42
+ },
43
+ "files": [
44
+ "dist/sdk",
45
+ "README.md",
46
+ "LICENSE"
47
+ ],
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "sideEffects": false,
52
+ "peerDependencies": {
53
+ "react": ">=17",
54
+ "vue": ">=3"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "react": {
58
+ "optional": true
59
+ },
60
+ "vue": {
61
+ "optional": true
62
+ }
63
+ },
64
+ "scripts": {
65
+ "dev": "vite",
66
+ "build:cdn": "tsc && vite build",
67
+ "build:sdk": "tsc -p tsconfig.sdk.json --noEmit && vite build --config vite.config.sdk.ts",
68
+ "build": "npm run build:cdn && npm run build:sdk",
69
+ "preview": "vite preview",
70
+ "test": "vitest run",
71
+ "test:watch": "vitest",
72
+ "prepublishOnly": "npm run build:sdk"
73
+ },
74
+ "devDependencies": {
75
+ "@types/react": "^19.2.14",
76
+ "@types/react-dom": "^19.2.3",
77
+ "@vitest/coverage-v8": "^4.1.6",
78
+ "jsdom": "^29.1.1",
79
+ "react": "^19.2.6",
80
+ "react-dom": "^19.2.6",
81
+ "typescript": "~6.0.2",
82
+ "vite": "^8.0.12",
83
+ "vite-plugin-dts": "^5.0.0",
84
+ "vitest": "^4.1.6",
85
+ "vue": "^3.5.34"
86
+ }
87
+ }