@buni.ai/chatbot-angular 1.0.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/dist/buni-chat-button.component.d.ts +16 -0
- package/dist/buni-chat-button.component.d.ts.map +1 -0
- package/dist/buni-chat-widget.component.d.ts +16 -0
- package/dist/buni-chat-widget.component.d.ts.map +1 -0
- package/dist/buni-chat.module.d.ts +3 -0
- package/dist/buni-chat.module.d.ts.map +1 -0
- package/dist/buni-chat.service.d.ts +29 -0
- package/dist/buni-chat.service.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +564 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +564 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EventEmitter } from '@angular/core';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { BuniChatService } from './buni-chat.service';
|
|
4
|
+
export declare class BuniChatButtonComponent {
|
|
5
|
+
private buniChatService;
|
|
6
|
+
openText: string;
|
|
7
|
+
closeText: string;
|
|
8
|
+
showText: boolean;
|
|
9
|
+
clicked: EventEmitter<boolean>;
|
|
10
|
+
isOpen$: Observable<boolean>;
|
|
11
|
+
isReady$: Observable<boolean>;
|
|
12
|
+
unreadCount$: Observable<number>;
|
|
13
|
+
constructor(buniChatService: BuniChatService);
|
|
14
|
+
handleClick(): void;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=buni-chat-button.component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buni-chat-button.component.d.ts","sourceRoot":"","sources":["../src/buni-chat-button.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,YAAY,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,qBA0Fa,uBAAuB;IAUtB,OAAO,CAAC,eAAe;IAT1B,QAAQ,SAAkB;IAC1B,SAAS,SAAgB;IACzB,QAAQ,UAAQ;IACf,OAAO,wBAA+B;IAEhD,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC7B,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC9B,YAAY,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;gBAEb,eAAe,EAAE,eAAe;IAMpD,WAAW,IAAI,IAAI;CAMpB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OnInit, OnDestroy } from '@angular/core';
|
|
2
|
+
import { BuniChatService } from './buni-chat.service';
|
|
3
|
+
import { BuniChatOptions } from '@buni.ai/chatbot-core';
|
|
4
|
+
export declare class BuniChatWidgetComponent implements OnInit, OnDestroy {
|
|
5
|
+
private buniChatService;
|
|
6
|
+
token: string;
|
|
7
|
+
config?: BuniChatOptions['config'];
|
|
8
|
+
onReady?: BuniChatOptions['onReady'];
|
|
9
|
+
onNewMessage?: BuniChatOptions['onNewMessage'];
|
|
10
|
+
onVisibilityChanged?: BuniChatOptions['onVisibilityChanged'];
|
|
11
|
+
onError?: BuniChatOptions['onError'];
|
|
12
|
+
constructor(buniChatService: BuniChatService);
|
|
13
|
+
ngOnInit(): Promise<void>;
|
|
14
|
+
ngOnDestroy(): void;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=buni-chat-widget.component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buni-chat-widget.component.d.ts","sourceRoot":"","sources":["../src/buni-chat-widget.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,qBASa,uBAAwB,YAAW,MAAM,EAAE,SAAS;IAQnD,OAAO,CAAC,eAAe;IAP1B,KAAK,EAAG,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;IACnC,OAAO,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACrC,YAAY,CAAC,EAAE,eAAe,CAAC,cAAc,CAAC,CAAC;IAC/C,mBAAmB,CAAC,EAAE,eAAe,CAAC,qBAAqB,CAAC,CAAC;IAC7D,OAAO,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;gBAE1B,eAAe,EAAE,eAAe;IAE9C,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAa/B,WAAW,IAAI,IAAI;CAGpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buni-chat.module.d.ts","sourceRoot":"","sources":["../src/buni-chat.module.ts"],"names":[],"mappings":"AAMA,qBAgBa,cAAc;CAAG"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { BuniChatOptions, BuniChatState, CustomerData, SessionVariables } from '@buni.ai/chatbot-core';
|
|
3
|
+
export declare class BuniChatService {
|
|
4
|
+
private widget;
|
|
5
|
+
private stateSubject;
|
|
6
|
+
private readySubject;
|
|
7
|
+
constructor();
|
|
8
|
+
initialize(options: BuniChatOptions): Promise<void>;
|
|
9
|
+
private setupEventListeners;
|
|
10
|
+
get state$(): Observable<BuniChatState>;
|
|
11
|
+
get isReady$(): Observable<boolean>;
|
|
12
|
+
get isOpen$(): Observable<boolean>;
|
|
13
|
+
get unreadCount$(): Observable<number>;
|
|
14
|
+
show(): void;
|
|
15
|
+
hide(): void;
|
|
16
|
+
toggle(): void;
|
|
17
|
+
minimize(): void;
|
|
18
|
+
maximize(): void;
|
|
19
|
+
setCustomerData(data: CustomerData): void;
|
|
20
|
+
getCustomerData(): CustomerData | null;
|
|
21
|
+
setSessionVariables(variables: SessionVariables): void;
|
|
22
|
+
getSessionVariables(): SessionVariables | null;
|
|
23
|
+
sendMessage(message: string): void;
|
|
24
|
+
clearChat(): void;
|
|
25
|
+
on(event: string, callback: Function): void;
|
|
26
|
+
off(event: string, callback?: Function): void;
|
|
27
|
+
destroy(): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=buni-chat.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buni-chat.service.d.ts","sourceRoot":"","sources":["../src/buni-chat.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,UAAU,EAAE,MAAM,MAAM,CAAC;AAEnD,OAAO,EAEL,eAAe,EACf,aAAa,EACb,YAAY,EACZ,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAE/B,qBAGa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,YAAY,CAKjB;IACH,OAAO,CAAC,YAAY,CAAuC;;IAMrD,UAAU,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAYzD,OAAO,CAAC,mBAAmB;IAa3B,IAAI,MAAM,IAAI,UAAU,CAAC,aAAa,CAAC,CAEtC;IAED,IAAI,QAAQ,IAAI,UAAU,CAAC,OAAO,CAAC,CAElC;IAED,IAAI,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAIjC;IAED,IAAI,YAAY,IAAI,UAAU,CAAC,MAAM,CAAC,CAIrC;IAGD,IAAI,IAAI,IAAI;IAIZ,IAAI,IAAI,IAAI;IAIZ,MAAM,IAAI,IAAI;IAId,QAAQ,IAAI,IAAI;IAIhB,QAAQ,IAAI,IAAI;IAKhB,eAAe,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAIzC,eAAe,IAAI,YAAY,GAAG,IAAI;IAItC,mBAAmB,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI;IAItD,mBAAmB,IAAI,gBAAgB,GAAG,IAAI;IAK9C,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIlC,SAAS,IAAI,IAAI;IAKjB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAI3C,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI;IAK7C,OAAO,IAAI,IAAI;CAKhB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './buni-chat.service';
|
|
2
|
+
export * from './buni-chat-widget.component';
|
|
3
|
+
export * from './buni-chat-button.component';
|
|
4
|
+
export * from './buni-chat.module';
|
|
5
|
+
export type { BuniChatConfig, BuniChatOptions, BuniChatState, CustomerData, SessionVariables, BuniChatAPI, BuniChatEvents } from '@buni.ai/chatbot-core';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AAGnC,YAAY,EACV,cAAc,EACd,eAAe,EACf,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,cAAc,EACf,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
import { Injectable, Input, Component, Output, EventEmitter, NgModule } from '@angular/core';
|
|
2
|
+
import { BehaviorSubject } from 'rxjs';
|
|
3
|
+
import { map } from 'rxjs/operators';
|
|
4
|
+
import { CommonModule } from '@angular/common';
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function __decorate(decorators, target, key, desc) {
|
|
24
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
25
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
26
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
27
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function __metadata(metadataKey, metadataValue) {
|
|
31
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
35
|
+
var e = new Error(message);
|
|
36
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Core widget loader class
|
|
40
|
+
class BuniChatWidget {
|
|
41
|
+
constructor() {
|
|
42
|
+
this.state = {
|
|
43
|
+
isOpen: false,
|
|
44
|
+
isLoaded: false,
|
|
45
|
+
isMinimized: false,
|
|
46
|
+
unreadCount: 0,
|
|
47
|
+
};
|
|
48
|
+
this.eventListeners = new Map();
|
|
49
|
+
this.widgetElement = null;
|
|
50
|
+
this.customerData = null;
|
|
51
|
+
this.sessionVariables = null;
|
|
52
|
+
}
|
|
53
|
+
async initialize(options) {
|
|
54
|
+
this.options = options;
|
|
55
|
+
try {
|
|
56
|
+
await this.loadWidget();
|
|
57
|
+
this.state.isLoaded = true;
|
|
58
|
+
this.emit("ready", { timestamp: Date.now() });
|
|
59
|
+
if (options.onReady) {
|
|
60
|
+
options.onReady({ timestamp: Date.now() });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
65
|
+
this.emit("error", { error: errorObj, context: "initialization" });
|
|
66
|
+
if (options.onError) {
|
|
67
|
+
options.onError(errorObj);
|
|
68
|
+
}
|
|
69
|
+
throw errorObj;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async loadWidget() {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
// Check if widget is already loaded
|
|
75
|
+
if (window.BuniChat) {
|
|
76
|
+
resolve();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// Load the widget script dynamically
|
|
80
|
+
const script = document.createElement("script");
|
|
81
|
+
script.src = `${this.getBaseUrl()}/api/embed/widget?token=${encodeURIComponent(this.options.token)}`;
|
|
82
|
+
script.async = true;
|
|
83
|
+
script.onload = () => {
|
|
84
|
+
// Initialize the actual widget
|
|
85
|
+
this.initializeWidgetAPI();
|
|
86
|
+
resolve();
|
|
87
|
+
};
|
|
88
|
+
script.onerror = () => {
|
|
89
|
+
reject(new Error("Failed to load BuniAI widget script"));
|
|
90
|
+
};
|
|
91
|
+
document.head.appendChild(script);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
initializeWidgetAPI() {
|
|
95
|
+
// Set up communication with the loaded widget
|
|
96
|
+
if (window.BuniChat) {
|
|
97
|
+
// Configure the widget with our options
|
|
98
|
+
window.BuniChat.configure(this.options.config || {});
|
|
99
|
+
// Set up event forwarding from the widget to our event system
|
|
100
|
+
window.BuniChat.on("visibility_changed", (data) => {
|
|
101
|
+
this.state.isOpen = data.visibility === "visible";
|
|
102
|
+
this.emit("visibility_changed", data);
|
|
103
|
+
if (this.options.onVisibilityChanged) {
|
|
104
|
+
this.options.onVisibilityChanged(data);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
window.BuniChat.on("new_message", (data) => {
|
|
108
|
+
if (data.isFromBot) {
|
|
109
|
+
this.state.unreadCount++;
|
|
110
|
+
}
|
|
111
|
+
this.emit("new_message", data);
|
|
112
|
+
if (this.options.onNewMessage) {
|
|
113
|
+
this.options.onNewMessage(data);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
window.BuniChat.on("minimized", (data) => {
|
|
117
|
+
this.state.isMinimized = true;
|
|
118
|
+
this.emit("minimized", data);
|
|
119
|
+
});
|
|
120
|
+
window.BuniChat.on("maximized", (data) => {
|
|
121
|
+
this.state.isMinimized = false;
|
|
122
|
+
this.emit("maximized", data);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
getBaseUrl() {
|
|
127
|
+
// Return the base URL for the BuniAI platform
|
|
128
|
+
return globalThis.BUNI_API_URL || window.location.origin;
|
|
129
|
+
}
|
|
130
|
+
destroy() {
|
|
131
|
+
if (window.BuniChat) {
|
|
132
|
+
window.BuniChat.destroy();
|
|
133
|
+
}
|
|
134
|
+
if (this.widgetElement) {
|
|
135
|
+
this.widgetElement.remove();
|
|
136
|
+
this.widgetElement = null;
|
|
137
|
+
}
|
|
138
|
+
this.eventListeners.clear();
|
|
139
|
+
this.state.isLoaded = false;
|
|
140
|
+
this.customerData = null;
|
|
141
|
+
this.sessionVariables = null;
|
|
142
|
+
}
|
|
143
|
+
show() {
|
|
144
|
+
if (window.BuniChat) {
|
|
145
|
+
window.BuniChat.show();
|
|
146
|
+
}
|
|
147
|
+
this.state.isOpen = true;
|
|
148
|
+
this.state.unreadCount = 0;
|
|
149
|
+
this.emit("visibility_changed", { visibility: "visible" });
|
|
150
|
+
}
|
|
151
|
+
hide() {
|
|
152
|
+
if (window.BuniChat) {
|
|
153
|
+
window.BuniChat.hide();
|
|
154
|
+
}
|
|
155
|
+
this.state.isOpen = false;
|
|
156
|
+
this.emit("visibility_changed", { visibility: "hidden" });
|
|
157
|
+
}
|
|
158
|
+
toggle() {
|
|
159
|
+
this.state.isOpen ? this.hide() : this.show();
|
|
160
|
+
}
|
|
161
|
+
minimize() {
|
|
162
|
+
if (window.BuniChat) {
|
|
163
|
+
window.BuniChat.minimize();
|
|
164
|
+
}
|
|
165
|
+
this.state.isMinimized = true;
|
|
166
|
+
this.emit("minimized", { timestamp: Date.now() });
|
|
167
|
+
}
|
|
168
|
+
maximize() {
|
|
169
|
+
if (window.BuniChat) {
|
|
170
|
+
window.BuniChat.maximize();
|
|
171
|
+
}
|
|
172
|
+
this.state.isMinimized = false;
|
|
173
|
+
this.emit("maximized", { timestamp: Date.now() });
|
|
174
|
+
}
|
|
175
|
+
setCustomerData(data) {
|
|
176
|
+
this.customerData = { ...this.customerData, ...data };
|
|
177
|
+
if (window.BuniChat) {
|
|
178
|
+
window.BuniChat.setCustomerData(this.customerData);
|
|
179
|
+
}
|
|
180
|
+
this.emit("customer_data_updated", { data: this.customerData });
|
|
181
|
+
}
|
|
182
|
+
getCustomerData() {
|
|
183
|
+
return this.customerData ? { ...this.customerData } : null;
|
|
184
|
+
}
|
|
185
|
+
setSessionVariables(variables) {
|
|
186
|
+
this.sessionVariables = { ...this.sessionVariables, ...variables };
|
|
187
|
+
if (window.BuniChat) {
|
|
188
|
+
window.BuniChat.setSessionVariables(this.sessionVariables);
|
|
189
|
+
}
|
|
190
|
+
this.emit("session_updated", { variables: this.sessionVariables });
|
|
191
|
+
}
|
|
192
|
+
getSessionVariables() {
|
|
193
|
+
return this.sessionVariables ? { ...this.sessionVariables } : null;
|
|
194
|
+
}
|
|
195
|
+
sendMessage(message) {
|
|
196
|
+
if (window.BuniChat) {
|
|
197
|
+
window.BuniChat.sendMessage(message);
|
|
198
|
+
}
|
|
199
|
+
const messageData = {
|
|
200
|
+
message,
|
|
201
|
+
isFromBot: false,
|
|
202
|
+
timestamp: Date.now(),
|
|
203
|
+
messageId: `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
204
|
+
};
|
|
205
|
+
this.emit("new_message", messageData);
|
|
206
|
+
}
|
|
207
|
+
clearChat() {
|
|
208
|
+
if (window.BuniChat) {
|
|
209
|
+
window.BuniChat.clearChat();
|
|
210
|
+
}
|
|
211
|
+
this.state.unreadCount = 0;
|
|
212
|
+
}
|
|
213
|
+
on(event, callback) {
|
|
214
|
+
if (!this.eventListeners.has(event)) {
|
|
215
|
+
this.eventListeners.set(event, []);
|
|
216
|
+
}
|
|
217
|
+
this.eventListeners.get(event).push(callback);
|
|
218
|
+
}
|
|
219
|
+
off(event, callback) {
|
|
220
|
+
const listeners = this.eventListeners.get(event);
|
|
221
|
+
if (!listeners)
|
|
222
|
+
return;
|
|
223
|
+
if (callback) {
|
|
224
|
+
const index = listeners.indexOf(callback);
|
|
225
|
+
if (index > -1) {
|
|
226
|
+
listeners.splice(index, 1);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
this.eventListeners.set(event, []);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
emit(event, data) {
|
|
234
|
+
const listeners = this.eventListeners.get(event);
|
|
235
|
+
if (listeners) {
|
|
236
|
+
listeners.forEach((callback) => {
|
|
237
|
+
try {
|
|
238
|
+
callback(data);
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
console.error(`Error in event listener for ${event}:`, error);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
getState() {
|
|
247
|
+
return { ...this.state };
|
|
248
|
+
}
|
|
249
|
+
isReady() {
|
|
250
|
+
return this.state.isLoaded;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// @buni.ai/chatbot-angular - Angular services and components
|
|
255
|
+
let BuniChatService = class BuniChatService {
|
|
256
|
+
constructor() {
|
|
257
|
+
this.stateSubject = new BehaviorSubject({
|
|
258
|
+
isOpen: false,
|
|
259
|
+
isLoaded: false,
|
|
260
|
+
isMinimized: false,
|
|
261
|
+
unreadCount: 0
|
|
262
|
+
});
|
|
263
|
+
this.readySubject = new BehaviorSubject(false);
|
|
264
|
+
this.widget = new BuniChatWidget();
|
|
265
|
+
}
|
|
266
|
+
async initialize(options) {
|
|
267
|
+
try {
|
|
268
|
+
await this.widget.initialize(options);
|
|
269
|
+
this.readySubject.next(true);
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
console.error('Failed to initialize BuniChat widget:', error);
|
|
273
|
+
throw error;
|
|
274
|
+
}
|
|
275
|
+
this.setupEventListeners();
|
|
276
|
+
}
|
|
277
|
+
setupEventListeners() {
|
|
278
|
+
const updateState = () => {
|
|
279
|
+
this.stateSubject.next(this.widget.getState());
|
|
280
|
+
};
|
|
281
|
+
this.widget.on('ready', updateState);
|
|
282
|
+
this.widget.on('visibility_changed', updateState);
|
|
283
|
+
this.widget.on('minimized', updateState);
|
|
284
|
+
this.widget.on('maximized', updateState);
|
|
285
|
+
this.widget.on('new_message', updateState);
|
|
286
|
+
}
|
|
287
|
+
// State observables
|
|
288
|
+
get state$() {
|
|
289
|
+
return this.stateSubject.asObservable();
|
|
290
|
+
}
|
|
291
|
+
get isReady$() {
|
|
292
|
+
return this.readySubject.asObservable();
|
|
293
|
+
}
|
|
294
|
+
get isOpen$() {
|
|
295
|
+
return this.stateSubject.pipe(map(state => state.isOpen));
|
|
296
|
+
}
|
|
297
|
+
get unreadCount$() {
|
|
298
|
+
return this.stateSubject.pipe(map(state => state.unreadCount));
|
|
299
|
+
}
|
|
300
|
+
// Widget control methods
|
|
301
|
+
show() {
|
|
302
|
+
this.widget.show();
|
|
303
|
+
}
|
|
304
|
+
hide() {
|
|
305
|
+
this.widget.hide();
|
|
306
|
+
}
|
|
307
|
+
toggle() {
|
|
308
|
+
this.widget.toggle();
|
|
309
|
+
}
|
|
310
|
+
minimize() {
|
|
311
|
+
this.widget.minimize();
|
|
312
|
+
}
|
|
313
|
+
maximize() {
|
|
314
|
+
this.widget.maximize();
|
|
315
|
+
}
|
|
316
|
+
// Data methods
|
|
317
|
+
setCustomerData(data) {
|
|
318
|
+
this.widget.setCustomerData(data);
|
|
319
|
+
}
|
|
320
|
+
getCustomerData() {
|
|
321
|
+
return this.widget.getCustomerData();
|
|
322
|
+
}
|
|
323
|
+
setSessionVariables(variables) {
|
|
324
|
+
this.widget.setSessionVariables(variables);
|
|
325
|
+
}
|
|
326
|
+
getSessionVariables() {
|
|
327
|
+
return this.widget.getSessionVariables();
|
|
328
|
+
}
|
|
329
|
+
// Message methods
|
|
330
|
+
sendMessage(message) {
|
|
331
|
+
this.widget.sendMessage(message);
|
|
332
|
+
}
|
|
333
|
+
clearChat() {
|
|
334
|
+
this.widget.clearChat();
|
|
335
|
+
}
|
|
336
|
+
// Event methods
|
|
337
|
+
on(event, callback) {
|
|
338
|
+
this.widget.on(event, callback);
|
|
339
|
+
}
|
|
340
|
+
off(event, callback) {
|
|
341
|
+
this.widget.off(event, callback);
|
|
342
|
+
}
|
|
343
|
+
// Cleanup
|
|
344
|
+
destroy() {
|
|
345
|
+
this.widget.destroy();
|
|
346
|
+
this.stateSubject.complete();
|
|
347
|
+
this.readySubject.complete();
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
BuniChatService = __decorate([
|
|
351
|
+
Injectable({
|
|
352
|
+
providedIn: 'root'
|
|
353
|
+
}),
|
|
354
|
+
__metadata("design:paramtypes", [])
|
|
355
|
+
], BuniChatService);
|
|
356
|
+
|
|
357
|
+
let BuniChatWidgetComponent = class BuniChatWidgetComponent {
|
|
358
|
+
constructor(buniChatService) {
|
|
359
|
+
this.buniChatService = buniChatService;
|
|
360
|
+
}
|
|
361
|
+
async ngOnInit() {
|
|
362
|
+
if (this.token) {
|
|
363
|
+
await this.buniChatService.initialize({
|
|
364
|
+
token: this.token,
|
|
365
|
+
config: this.config,
|
|
366
|
+
onReady: this.onReady,
|
|
367
|
+
onNewMessage: this.onNewMessage,
|
|
368
|
+
onVisibilityChanged: this.onVisibilityChanged,
|
|
369
|
+
onError: this.onError,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
ngOnDestroy() {
|
|
374
|
+
this.buniChatService.destroy();
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
__decorate([
|
|
378
|
+
Input(),
|
|
379
|
+
__metadata("design:type", String)
|
|
380
|
+
], BuniChatWidgetComponent.prototype, "token", void 0);
|
|
381
|
+
__decorate([
|
|
382
|
+
Input(),
|
|
383
|
+
__metadata("design:type", Object)
|
|
384
|
+
], BuniChatWidgetComponent.prototype, "config", void 0);
|
|
385
|
+
__decorate([
|
|
386
|
+
Input(),
|
|
387
|
+
__metadata("design:type", Object)
|
|
388
|
+
], BuniChatWidgetComponent.prototype, "onReady", void 0);
|
|
389
|
+
__decorate([
|
|
390
|
+
Input(),
|
|
391
|
+
__metadata("design:type", Object)
|
|
392
|
+
], BuniChatWidgetComponent.prototype, "onNewMessage", void 0);
|
|
393
|
+
__decorate([
|
|
394
|
+
Input(),
|
|
395
|
+
__metadata("design:type", Object)
|
|
396
|
+
], BuniChatWidgetComponent.prototype, "onVisibilityChanged", void 0);
|
|
397
|
+
__decorate([
|
|
398
|
+
Input(),
|
|
399
|
+
__metadata("design:type", Object)
|
|
400
|
+
], BuniChatWidgetComponent.prototype, "onError", void 0);
|
|
401
|
+
BuniChatWidgetComponent = __decorate([
|
|
402
|
+
Component({
|
|
403
|
+
selector: 'buni-chat-widget',
|
|
404
|
+
template: `<div id="buni-chat-widget-container"></div>`,
|
|
405
|
+
styles: [`
|
|
406
|
+
:host {
|
|
407
|
+
display: block;
|
|
408
|
+
}
|
|
409
|
+
`]
|
|
410
|
+
}),
|
|
411
|
+
__metadata("design:paramtypes", [BuniChatService])
|
|
412
|
+
], BuniChatWidgetComponent);
|
|
413
|
+
|
|
414
|
+
let BuniChatButtonComponent = class BuniChatButtonComponent {
|
|
415
|
+
constructor(buniChatService) {
|
|
416
|
+
this.buniChatService = buniChatService;
|
|
417
|
+
this.openText = 'Chat with us';
|
|
418
|
+
this.closeText = 'Close chat';
|
|
419
|
+
this.showText = true;
|
|
420
|
+
this.clicked = new EventEmitter();
|
|
421
|
+
this.isOpen$ = this.buniChatService.isOpen$;
|
|
422
|
+
this.isReady$ = this.buniChatService.isReady$;
|
|
423
|
+
this.unreadCount$ = this.buniChatService.unreadCount$;
|
|
424
|
+
}
|
|
425
|
+
handleClick() {
|
|
426
|
+
this.buniChatService.toggle();
|
|
427
|
+
this.isOpen$.subscribe(isOpen => {
|
|
428
|
+
this.clicked.emit(isOpen);
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
__decorate([
|
|
433
|
+
Input(),
|
|
434
|
+
__metadata("design:type", Object)
|
|
435
|
+
], BuniChatButtonComponent.prototype, "openText", void 0);
|
|
436
|
+
__decorate([
|
|
437
|
+
Input(),
|
|
438
|
+
__metadata("design:type", Object)
|
|
439
|
+
], BuniChatButtonComponent.prototype, "closeText", void 0);
|
|
440
|
+
__decorate([
|
|
441
|
+
Input(),
|
|
442
|
+
__metadata("design:type", Object)
|
|
443
|
+
], BuniChatButtonComponent.prototype, "showText", void 0);
|
|
444
|
+
__decorate([
|
|
445
|
+
Output(),
|
|
446
|
+
__metadata("design:type", Object)
|
|
447
|
+
], BuniChatButtonComponent.prototype, "clicked", void 0);
|
|
448
|
+
BuniChatButtonComponent = __decorate([
|
|
449
|
+
Component({
|
|
450
|
+
selector: 'buni-chat-button',
|
|
451
|
+
template: `
|
|
452
|
+
<button
|
|
453
|
+
class="buni-chat-button"
|
|
454
|
+
[class.buni-chat-button--open]="isOpen$ | async"
|
|
455
|
+
(click)="handleClick()"
|
|
456
|
+
[disabled]="!(isReady$ | async)"
|
|
457
|
+
>
|
|
458
|
+
<span class="buni-chat-button__icon">
|
|
459
|
+
{{ (isOpen$ | async) ? '✕' : '💬' }}
|
|
460
|
+
</span>
|
|
461
|
+
<span class="buni-chat-button__text" *ngIf="showText">
|
|
462
|
+
{{ (isOpen$ | async) ? closeText : openText }}
|
|
463
|
+
</span>
|
|
464
|
+
<span
|
|
465
|
+
class="buni-chat-button__badge"
|
|
466
|
+
*ngIf="(unreadCount$ | async)! > 0 && !(isOpen$ | async)"
|
|
467
|
+
>
|
|
468
|
+
{{ unreadCount$ | async }}
|
|
469
|
+
</span>
|
|
470
|
+
</button>
|
|
471
|
+
`,
|
|
472
|
+
styles: [`
|
|
473
|
+
.buni-chat-button {
|
|
474
|
+
position: fixed;
|
|
475
|
+
bottom: 20px;
|
|
476
|
+
right: 20px;
|
|
477
|
+
background: #007bff;
|
|
478
|
+
color: white;
|
|
479
|
+
border: none;
|
|
480
|
+
border-radius: 50px;
|
|
481
|
+
padding: 12px 20px;
|
|
482
|
+
cursor: pointer;
|
|
483
|
+
box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
|
|
484
|
+
display: flex;
|
|
485
|
+
align-items: center;
|
|
486
|
+
gap: 8px;
|
|
487
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
488
|
+
font-size: 14px;
|
|
489
|
+
transition: all 0.3s ease;
|
|
490
|
+
z-index: 1000;
|
|
491
|
+
position: relative;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
.buni-chat-button:hover {
|
|
495
|
+
background: #0056b3;
|
|
496
|
+
transform: translateY(-2px);
|
|
497
|
+
box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
.buni-chat-button:disabled {
|
|
501
|
+
opacity: 0.6;
|
|
502
|
+
cursor: not-allowed;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
.buni-chat-button--open {
|
|
506
|
+
background: #dc3545;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
.buni-chat-button--open:hover {
|
|
510
|
+
background: #c82333;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
.buni-chat-button__icon {
|
|
514
|
+
font-size: 16px;
|
|
515
|
+
line-height: 1;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
.buni-chat-button__text {
|
|
519
|
+
font-weight: 500;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
.buni-chat-button__badge {
|
|
523
|
+
position: absolute;
|
|
524
|
+
top: -5px;
|
|
525
|
+
right: -5px;
|
|
526
|
+
background: #dc3545;
|
|
527
|
+
color: white;
|
|
528
|
+
border-radius: 50%;
|
|
529
|
+
width: 20px;
|
|
530
|
+
height: 20px;
|
|
531
|
+
font-size: 12px;
|
|
532
|
+
display: flex;
|
|
533
|
+
align-items: center;
|
|
534
|
+
justify-content: center;
|
|
535
|
+
font-weight: bold;
|
|
536
|
+
}
|
|
537
|
+
`]
|
|
538
|
+
}),
|
|
539
|
+
__metadata("design:paramtypes", [BuniChatService])
|
|
540
|
+
], BuniChatButtonComponent);
|
|
541
|
+
|
|
542
|
+
let BuniChatModule = class BuniChatModule {
|
|
543
|
+
};
|
|
544
|
+
BuniChatModule = __decorate([
|
|
545
|
+
NgModule({
|
|
546
|
+
declarations: [
|
|
547
|
+
BuniChatWidgetComponent,
|
|
548
|
+
BuniChatButtonComponent
|
|
549
|
+
],
|
|
550
|
+
imports: [
|
|
551
|
+
CommonModule
|
|
552
|
+
],
|
|
553
|
+
exports: [
|
|
554
|
+
BuniChatWidgetComponent,
|
|
555
|
+
BuniChatButtonComponent
|
|
556
|
+
],
|
|
557
|
+
providers: [
|
|
558
|
+
BuniChatService
|
|
559
|
+
]
|
|
560
|
+
})
|
|
561
|
+
], BuniChatModule);
|
|
562
|
+
|
|
563
|
+
export { BuniChatButtonComponent, BuniChatModule, BuniChatService, BuniChatWidgetComponent };
|
|
564
|
+
//# sourceMappingURL=index.esm.js.map
|