@buni.ai/chatbot-angular 1.0.24 → 1.0.25
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/dist/index.esm.js +112 -15
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +112 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -58,6 +58,31 @@ class BuniChatWidget {
|
|
|
58
58
|
this.chatTargetOrigin = null;
|
|
59
59
|
this.handshakeComplete = false;
|
|
60
60
|
this.outboundMessageQueue = [];
|
|
61
|
+
this.displayMode = "hidden";
|
|
62
|
+
this.serverBehavior = {};
|
|
63
|
+
}
|
|
64
|
+
isMinimalModeEnabled() {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
if (typeof ((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.enableMinimalMode) === "boolean") {
|
|
67
|
+
return this.options.config.enableMinimalMode;
|
|
68
|
+
}
|
|
69
|
+
return Boolean(this.serverBehavior.enableMinimalMode);
|
|
70
|
+
}
|
|
71
|
+
syncServerBehaviorFromData(data) {
|
|
72
|
+
if (!data || typeof data !== "object") {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const behaviorCandidate = data.behavior && typeof data.behavior === "object"
|
|
76
|
+
? data.behavior
|
|
77
|
+
: data;
|
|
78
|
+
if (typeof behaviorCandidate.enableMinimalMode === "boolean") {
|
|
79
|
+
this.serverBehavior.enableMinimalMode = behaviorCandidate.enableMinimalMode;
|
|
80
|
+
}
|
|
81
|
+
if (behaviorCandidate.defaultMode === "full" ||
|
|
82
|
+
behaviorCandidate.defaultMode === "minimal" ||
|
|
83
|
+
behaviorCandidate.defaultMode === "hidden") {
|
|
84
|
+
this.serverBehavior.defaultMode = behaviorCandidate.defaultMode;
|
|
85
|
+
}
|
|
61
86
|
}
|
|
62
87
|
async initialize(options) {
|
|
63
88
|
this.options = options;
|
|
@@ -221,6 +246,15 @@ class BuniChatWidget {
|
|
|
221
246
|
params.set("startButtonText", config.startButtonText);
|
|
222
247
|
if (config.preChatFormFields)
|
|
223
248
|
params.set("preChatFormFields", JSON.stringify(config.preChatFormFields));
|
|
249
|
+
if (config.enableMinimalMode !== undefined) {
|
|
250
|
+
params.set("enableMinimalMode", String(config.enableMinimalMode));
|
|
251
|
+
}
|
|
252
|
+
if (config.defaultMode) {
|
|
253
|
+
params.set("defaultMode", config.defaultMode);
|
|
254
|
+
}
|
|
255
|
+
if (config.autoMessages && Array.isArray(config.autoMessages)) {
|
|
256
|
+
params.set("autoMessages", JSON.stringify(config.autoMessages));
|
|
257
|
+
}
|
|
224
258
|
chatIframe.src = `${this.getBaseUrl()}/embed/chat?${params.toString()}`;
|
|
225
259
|
// Chat iframe styling - initially hidden
|
|
226
260
|
chatIframe.style.cssText = `
|
|
@@ -261,13 +295,15 @@ class BuniChatWidget {
|
|
|
261
295
|
this.triggerIframe = triggerIframe;
|
|
262
296
|
this.chatIframe = chatIframe;
|
|
263
297
|
this.state.isMinimized = true;
|
|
298
|
+
this.state.displayMode = "hidden";
|
|
299
|
+
this.displayMode = "hidden";
|
|
264
300
|
this.state.isLoaded = true;
|
|
265
301
|
resolve();
|
|
266
302
|
};
|
|
267
303
|
};
|
|
268
304
|
// Listen for trigger and connection events
|
|
269
305
|
window.addEventListener("message", (event) => {
|
|
270
|
-
var _a, _b;
|
|
306
|
+
var _a, _b, _c, _d, _e, _f;
|
|
271
307
|
const payload = event.data;
|
|
272
308
|
if (!payload || typeof payload !== "object")
|
|
273
309
|
return;
|
|
@@ -278,20 +314,53 @@ class BuniChatWidget {
|
|
|
278
314
|
// Check if message is from chat iframe
|
|
279
315
|
if (event.source === ((_a = this.chatIframe) === null || _a === void 0 ? void 0 : _a.contentWindow) &&
|
|
280
316
|
event.origin === this.getBaseUrl()) {
|
|
317
|
+
this.syncServerBehaviorFromData(payload.data);
|
|
281
318
|
// Connection is ready, show the trigger button
|
|
282
319
|
if (container && !config.hideDefaultTrigger) {
|
|
283
320
|
container.style.display = "block";
|
|
284
321
|
}
|
|
285
322
|
// Emit connection_ready event for consumers
|
|
286
|
-
this.emit("connection_ready", {
|
|
323
|
+
this.emit("connection_ready", {
|
|
324
|
+
timestamp: Date.now(),
|
|
325
|
+
behavior: (_b = payload.data) === null || _b === void 0 ? void 0 : _b.behavior,
|
|
326
|
+
});
|
|
287
327
|
if (this.options.onConnectionReady &&
|
|
288
328
|
typeof this.options.onConnectionReady === "function") {
|
|
289
|
-
this.options.onConnectionReady({
|
|
329
|
+
this.options.onConnectionReady({
|
|
330
|
+
timestamp: Date.now(),
|
|
331
|
+
behavior: (_c = payload.data) === null || _c === void 0 ? void 0 : _c.behavior,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
break;
|
|
336
|
+
case "chatbot:close":
|
|
337
|
+
if (event.source === ((_d = this.chatIframe) === null || _d === void 0 ? void 0 : _d.contentWindow) &&
|
|
338
|
+
event.origin === this.getBaseUrl()) {
|
|
339
|
+
this.closeChat();
|
|
340
|
+
this.displayMode = "hidden";
|
|
341
|
+
this.state.displayMode = "hidden";
|
|
342
|
+
}
|
|
343
|
+
break;
|
|
344
|
+
case "chatbot:minimize":
|
|
345
|
+
if (event.source === ((_e = this.chatIframe) === null || _e === void 0 ? void 0 : _e.contentWindow) &&
|
|
346
|
+
event.origin === this.getBaseUrl()) {
|
|
347
|
+
if (this.isMinimalModeEnabled()) {
|
|
348
|
+
if (!this.state.isOpen) {
|
|
349
|
+
void this.openChat();
|
|
350
|
+
}
|
|
351
|
+
this.postMessageToWidget("minimize");
|
|
352
|
+
this.displayMode = "minimal";
|
|
353
|
+
this.state.displayMode = "minimal";
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
this.closeChat();
|
|
357
|
+
this.displayMode = "hidden";
|
|
358
|
+
this.state.displayMode = "hidden";
|
|
290
359
|
}
|
|
291
360
|
}
|
|
292
361
|
break;
|
|
293
362
|
case "trigger_clicked":
|
|
294
|
-
if (event.source === ((
|
|
363
|
+
if (event.source === ((_f = this.triggerIframe) === null || _f === void 0 ? void 0 : _f.contentWindow) &&
|
|
295
364
|
event.origin === window.location.origin) {
|
|
296
365
|
this.openChat();
|
|
297
366
|
}
|
|
@@ -301,13 +370,11 @@ class BuniChatWidget {
|
|
|
301
370
|
// Trigger the load event
|
|
302
371
|
// if by 10 seconds the ready message is not received, we want to manually, set the container to visible
|
|
303
372
|
setTimeout(() => {
|
|
304
|
-
if (
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
container.style.display = "block";
|
|
310
|
-
}
|
|
373
|
+
if (container &&
|
|
374
|
+
!config.hideDefaultTrigger &&
|
|
375
|
+
container.style.display === "none" &&
|
|
376
|
+
this.state.isOpen === false) {
|
|
377
|
+
container.style.display = "block";
|
|
311
378
|
}
|
|
312
379
|
}, 10000);
|
|
313
380
|
triggerIframe.src = "about:blank";
|
|
@@ -484,6 +551,8 @@ class BuniChatWidget {
|
|
|
484
551
|
this.chatIframe.style.visibility = "visible";
|
|
485
552
|
this.state.isMinimized = false;
|
|
486
553
|
this.state.isOpen = true;
|
|
554
|
+
this.displayMode = "full";
|
|
555
|
+
this.state.displayMode = "full";
|
|
487
556
|
this.emit("maximized", { timestamp: Date.now() });
|
|
488
557
|
}
|
|
489
558
|
closeChat() {
|
|
@@ -516,6 +585,8 @@ class BuniChatWidget {
|
|
|
516
585
|
this.triggerIframe.style.display = "block";
|
|
517
586
|
this.state.isMinimized = true;
|
|
518
587
|
this.state.isOpen = false;
|
|
588
|
+
this.displayMode = "hidden";
|
|
589
|
+
this.state.displayMode = "hidden";
|
|
519
590
|
this.emit("minimized", { timestamp: Date.now() });
|
|
520
591
|
}
|
|
521
592
|
getPositionStyles(position, isMinimized = false) {
|
|
@@ -607,8 +678,18 @@ class BuniChatWidget {
|
|
|
607
678
|
}
|
|
608
679
|
break;
|
|
609
680
|
case "minimized":
|
|
610
|
-
|
|
611
|
-
this.
|
|
681
|
+
this.syncServerBehaviorFromData(data);
|
|
682
|
+
if (this.isMinimalModeEnabled()) {
|
|
683
|
+
if (!this.state.isOpen) {
|
|
684
|
+
void this.openChat();
|
|
685
|
+
}
|
|
686
|
+
this.displayMode = "minimal";
|
|
687
|
+
this.state.displayMode = "minimal";
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
// Backward-compatible behavior.
|
|
691
|
+
this.closeChat();
|
|
692
|
+
}
|
|
612
693
|
break;
|
|
613
694
|
case "new_unread_message":
|
|
614
695
|
// Update unread count in trigger
|
|
@@ -743,10 +824,21 @@ class BuniChatWidget {
|
|
|
743
824
|
}
|
|
744
825
|
}
|
|
745
826
|
minimize() {
|
|
827
|
+
if (this.isMinimalModeEnabled()) {
|
|
828
|
+
if (!this.state.isOpen) {
|
|
829
|
+
void this.openChat();
|
|
830
|
+
}
|
|
831
|
+
this.postMessageToWidget("minimize");
|
|
832
|
+
this.displayMode = "minimal";
|
|
833
|
+
this.state.displayMode = "minimal";
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
746
836
|
this.closeChat();
|
|
747
837
|
}
|
|
748
838
|
maximize() {
|
|
749
|
-
this.openChat();
|
|
839
|
+
void this.openChat();
|
|
840
|
+
this.displayMode = "full";
|
|
841
|
+
this.state.displayMode = "full";
|
|
750
842
|
}
|
|
751
843
|
setCustomerData(data) {
|
|
752
844
|
this.customerData = { ...this.customerData, ...data };
|
|
@@ -787,6 +879,8 @@ class BuniChatWidget {
|
|
|
787
879
|
}
|
|
788
880
|
close() {
|
|
789
881
|
this.closeChat();
|
|
882
|
+
this.displayMode = "hidden";
|
|
883
|
+
this.state.displayMode = "hidden";
|
|
790
884
|
}
|
|
791
885
|
on(event, callback) {
|
|
792
886
|
if (!this.eventListeners.has(event)) {
|
|
@@ -822,7 +916,10 @@ class BuniChatWidget {
|
|
|
822
916
|
}
|
|
823
917
|
}
|
|
824
918
|
getState() {
|
|
825
|
-
return {
|
|
919
|
+
return {
|
|
920
|
+
...this.state,
|
|
921
|
+
displayMode: this.displayMode,
|
|
922
|
+
};
|
|
826
923
|
}
|
|
827
924
|
isReady() {
|
|
828
925
|
return this.state.isLoaded;
|