@buni.ai/chatbot-core 1.0.0 → 1.0.2

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 CHANGED
@@ -33,66 +33,159 @@ class BuniChatWidget {
33
33
  }
34
34
  async loadWidget() {
35
35
  return new Promise((resolve, reject) => {
36
- // Check if widget is already loaded
37
- if (window.BuniChat) {
38
- resolve();
39
- return;
40
- }
41
- // Load the widget script dynamically
42
- const script = document.createElement("script");
43
- script.src = `${this.getBaseUrl()}/api/embed/widget?token=${encodeURIComponent(this.options.token)}`;
44
- script.async = true;
45
- script.onload = () => {
46
- // Initialize the actual widget
47
- this.initializeWidgetAPI();
36
+ // Create container div for proper positioning
37
+ const container = document.createElement("div");
38
+ container.id = "buni-chat-widget-container";
39
+ const config = this.options.config || {};
40
+ container.style.cssText = `
41
+ position: fixed;
42
+ pointer-events: none;
43
+ z-index: 999999;
44
+ ${this.getPositionStyles(config.position || "bottom-right")}
45
+ display: ${config.hideDefaultTrigger ? "none" : "block"};
46
+ `;
47
+ // Create iframe for secure embedding
48
+ const iframe = document.createElement("iframe");
49
+ // Build URL with configuration parameters
50
+ const params = new URLSearchParams({
51
+ token: this.options.token,
52
+ embedded: "true",
53
+ theme: config.theme || "light",
54
+ width: String(config.width || "350px"),
55
+ height: String(config.height || "650px"),
56
+ primaryColor: config.primaryColor || "#795548",
57
+ secondaryColor: config.secondaryColor || "#A67D67",
58
+ position: config.position || "bottom-right",
59
+ showBranding: String(config.showBranding !== false),
60
+ autoOpen: String(config.autoOpen === true),
61
+ minimized: String(config.minimized === true),
62
+ allowMinimize: String(config.allowMinimize !== false),
63
+ showMinimize: String(config.showMinimize !== false),
64
+ enableFileUpload: String(config.enableFileUpload === true),
65
+ });
66
+ // Add optional parameters
67
+ if (config.customAvatar)
68
+ params.set("customAvatar", config.customAvatar);
69
+ if (config.companyName)
70
+ params.set("companyName", config.companyName);
71
+ if (config.welcomeMessage)
72
+ params.set("welcomeMessage", config.welcomeMessage);
73
+ if (config.triggerText)
74
+ params.set("triggerText", config.triggerText);
75
+ if (config.borderRadius)
76
+ params.set("borderRadius", config.borderRadius);
77
+ iframe.src = `${this.getBaseUrl()}/embed/chat?${params.toString()}`;
78
+ iframe.style.cssText = `
79
+ position: relative;
80
+ border: none;
81
+ width: ${config.width || "350px"};
82
+ height: ${config.height || "650px"};
83
+ border-radius: 12px;
84
+ transition: all 0.3s ease;
85
+ pointer-events: auto;
86
+ box-shadow: 0 4px 12px rgba(0,0,0,0.15);
87
+ `;
88
+ iframe.setAttribute("allow", "clipboard-write");
89
+ iframe.setAttribute("title", "BuniAI Chat Widget");
90
+ iframe.onload = () => {
91
+ this.widgetElement = container;
92
+ this.setupPostMessageAPI(iframe);
48
93
  resolve();
49
94
  };
50
- script.onerror = () => {
51
- reject(new Error("Failed to load BuniAI widget script"));
95
+ iframe.onerror = () => {
96
+ reject(new Error("Failed to load BuniAI widget iframe"));
52
97
  };
53
- document.head.appendChild(script);
98
+ container.appendChild(iframe);
99
+ document.body.appendChild(container);
54
100
  });
55
101
  }
56
- initializeWidgetAPI() {
57
- // Set up communication with the loaded widget
58
- if (window.BuniChat) {
59
- // Configure the widget with our options
60
- window.BuniChat.configure(this.options.config || {});
61
- // Set up event forwarding from the widget to our event system
62
- window.BuniChat.on("visibility_changed", (data) => {
63
- this.state.isOpen = data.visibility === "visible";
64
- this.emit("visibility_changed", data);
65
- if (this.options.onVisibilityChanged) {
66
- this.options.onVisibilityChanged(data);
67
- }
68
- });
69
- window.BuniChat.on("new_message", (data) => {
70
- if (data.isFromBot) {
71
- this.state.unreadCount++;
72
- }
73
- this.emit("new_message", data);
74
- if (this.options.onNewMessage) {
75
- this.options.onNewMessage(data);
76
- }
77
- });
78
- window.BuniChat.on("minimized", (data) => {
79
- this.state.isMinimized = true;
80
- this.emit("minimized", data);
81
- });
82
- window.BuniChat.on("maximized", (data) => {
83
- this.state.isMinimized = false;
84
- this.emit("maximized", data);
85
- });
102
+ getPositionStyles(position) {
103
+ switch (position) {
104
+ case "bottom-right":
105
+ return "bottom: 20px; right: 20px;";
106
+ case "bottom-left":
107
+ return "bottom: 20px; left: 20px;";
108
+ case "top-right":
109
+ return "top: 20px; right: 20px;";
110
+ case "top-left":
111
+ return "top: 20px; left: 20px;";
112
+ default:
113
+ return "bottom: 20px; right: 20px;";
114
+ }
115
+ }
116
+ setupPostMessageAPI(iframe) {
117
+ // Listen for messages from the iframe
118
+ window.addEventListener("message", (event) => {
119
+ // Verify origin for security
120
+ if (event.origin !== this.getBaseUrl()) {
121
+ return;
122
+ }
123
+ const { type, data } = event.data;
124
+ switch (type) {
125
+ case "ready":
126
+ this.state.isLoaded = true;
127
+ this.emit("ready", data);
128
+ if (this.options.onReady) {
129
+ this.options.onReady(data);
130
+ }
131
+ break;
132
+ case "visibility_changed":
133
+ this.state.isOpen = data.visibility === "visible";
134
+ this.emit("visibility_changed", data);
135
+ if (this.options.onVisibilityChanged) {
136
+ this.options.onVisibilityChanged(data);
137
+ }
138
+ break;
139
+ case "new_message":
140
+ if (data.isFromBot) {
141
+ this.state.unreadCount++;
142
+ }
143
+ this.emit("new_message", data);
144
+ if (this.options.onNewMessage) {
145
+ this.options.onNewMessage(data);
146
+ }
147
+ break;
148
+ case "minimized":
149
+ this.state.isMinimized = true;
150
+ this.emit("minimized", data);
151
+ break;
152
+ case "maximized":
153
+ this.state.isMinimized = false;
154
+ this.emit("maximized", data);
155
+ break;
156
+ case "customer_data_updated":
157
+ this.customerData = data;
158
+ this.emit("customer_data_updated", data);
159
+ break;
160
+ case "session_updated":
161
+ this.sessionVariables = data.variables;
162
+ this.emit("session_updated", data);
163
+ break;
164
+ case "error":
165
+ this.emit("error", data);
166
+ if (this.options.onError) {
167
+ this.options.onError(data.error);
168
+ }
169
+ break;
170
+ }
171
+ });
172
+ }
173
+ postMessageToWidget(type, data) {
174
+ var _a;
175
+ if (this.widgetElement && this.widgetElement instanceof HTMLIFrameElement) {
176
+ (_a = this.widgetElement.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage({ type, data }, this.getBaseUrl());
86
177
  }
87
178
  }
179
+ initializeWidgetAPI() {
180
+ // Widget API is now handled via postMessage in setupPostMessageAPI
181
+ // This method is kept for backward compatibility but no longer needed
182
+ }
88
183
  getBaseUrl() {
89
184
  // Return the base URL for the BuniAI platform
90
185
  return globalThis.BUNI_API_URL || window.location.origin;
91
186
  }
92
187
  destroy() {
93
- if (window.BuniChat) {
94
- window.BuniChat.destroy();
95
- }
188
+ this.postMessageToWidget("destroy");
96
189
  if (this.widgetElement) {
97
190
  this.widgetElement.remove();
98
191
  this.widgetElement = null;
@@ -103,16 +196,21 @@ class BuniChatWidget {
103
196
  this.sessionVariables = null;
104
197
  }
105
198
  show() {
106
- if (window.BuniChat) {
107
- window.BuniChat.show();
199
+ // Show the iframe if it was hidden (hideDefaultTrigger mode)
200
+ if (this.widgetElement instanceof HTMLIFrameElement) {
201
+ this.widgetElement.style.display = "block";
108
202
  }
203
+ this.postMessageToWidget("show");
109
204
  this.state.isOpen = true;
110
205
  this.state.unreadCount = 0;
111
206
  this.emit("visibility_changed", { visibility: "visible" });
112
207
  }
113
208
  hide() {
114
- if (window.BuniChat) {
115
- window.BuniChat.hide();
209
+ var _a;
210
+ this.postMessageToWidget("hide");
211
+ // If hideDefaultTrigger is enabled, completely hide the iframe
212
+ if (((_a = this.options.config) === null || _a === void 0 ? void 0 : _a.hideDefaultTrigger) && this.widgetElement instanceof HTMLIFrameElement) {
213
+ this.widgetElement.style.display = "none";
116
214
  }
117
215
  this.state.isOpen = false;
118
216
  this.emit("visibility_changed", { visibility: "hidden" });
@@ -121,24 +219,18 @@ class BuniChatWidget {
121
219
  this.state.isOpen ? this.hide() : this.show();
122
220
  }
123
221
  minimize() {
124
- if (window.BuniChat) {
125
- window.BuniChat.minimize();
126
- }
222
+ this.postMessageToWidget("minimize");
127
223
  this.state.isMinimized = true;
128
224
  this.emit("minimized", { timestamp: Date.now() });
129
225
  }
130
226
  maximize() {
131
- if (window.BuniChat) {
132
- window.BuniChat.maximize();
133
- }
227
+ this.postMessageToWidget("maximize");
134
228
  this.state.isMinimized = false;
135
229
  this.emit("maximized", { timestamp: Date.now() });
136
230
  }
137
231
  setCustomerData(data) {
138
232
  this.customerData = { ...this.customerData, ...data };
139
- if (window.BuniChat) {
140
- window.BuniChat.setCustomerData(this.customerData);
141
- }
233
+ this.postMessageToWidget("setCustomerData", this.customerData);
142
234
  this.emit("customer_data_updated", { data: this.customerData });
143
235
  }
144
236
  getCustomerData() {
@@ -146,18 +238,14 @@ class BuniChatWidget {
146
238
  }
147
239
  setSessionVariables(variables) {
148
240
  this.sessionVariables = { ...this.sessionVariables, ...variables };
149
- if (window.BuniChat) {
150
- window.BuniChat.setSessionVariables(this.sessionVariables);
151
- }
241
+ this.postMessageToWidget("setSessionVariables", this.sessionVariables);
152
242
  this.emit("session_updated", { variables: this.sessionVariables });
153
243
  }
154
244
  getSessionVariables() {
155
245
  return this.sessionVariables ? { ...this.sessionVariables } : null;
156
246
  }
157
247
  sendMessage(message) {
158
- if (window.BuniChat) {
159
- window.BuniChat.sendMessage(message);
160
- }
248
+ this.postMessageToWidget("sendMessage", { message });
161
249
  const messageData = {
162
250
  message,
163
251
  isFromBot: false,
@@ -167,9 +255,7 @@ class BuniChatWidget {
167
255
  this.emit("new_message", messageData);
168
256
  }
169
257
  clearChat() {
170
- if (window.BuniChat) {
171
- window.BuniChat.clearChat();
172
- }
258
+ this.postMessageToWidget("clearChat");
173
259
  this.state.unreadCount = 0;
174
260
  }
175
261
  on(event, callback) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/widget.ts","../src/index.ts"],"sourcesContent":["import {\n BuniChatAPI,\n BuniChatOptions,\n BuniChatState,\n CustomerData,\n SessionVariables,\n} from \"./types\";\n\n// Core widget loader class\nexport class BuniChatWidget implements BuniChatAPI {\n private options!: BuniChatOptions;\n private state: BuniChatState;\n private eventListeners: Map<string, Function[]>;\n private widgetElement: HTMLElement | null;\n private customerData: CustomerData | null;\n private sessionVariables: SessionVariables | null;\n\n constructor() {\n this.state = {\n isOpen: false,\n isLoaded: false,\n isMinimized: false,\n unreadCount: 0,\n };\n this.eventListeners = new Map();\n this.widgetElement = null;\n this.customerData = null;\n this.sessionVariables = null;\n }\n\n async initialize(options: BuniChatOptions): Promise<void> {\n this.options = options;\n\n try {\n await this.loadWidget();\n this.state.isLoaded = true;\n this.emit(\"ready\", { timestamp: Date.now() });\n\n if (options.onReady) {\n options.onReady({ timestamp: Date.now() });\n }\n } catch (error) {\n const errorObj =\n error instanceof Error ? error : new Error(String(error));\n this.emit(\"error\", { error: errorObj, context: \"initialization\" });\n\n if (options.onError) {\n options.onError(errorObj);\n }\n throw errorObj;\n }\n }\n\n private async loadWidget(): Promise<void> {\n return new Promise((resolve, reject) => {\n // Check if widget is already loaded\n if (window.BuniChat) {\n resolve();\n return;\n }\n\n // Load the widget script dynamically\n const script = document.createElement(\"script\");\n script.src = `${this.getBaseUrl()}/api/embed/widget?token=${encodeURIComponent(this.options.token)}`;\n script.async = true;\n\n script.onload = () => {\n // Initialize the actual widget\n this.initializeWidgetAPI();\n resolve();\n };\n\n script.onerror = () => {\n reject(new Error(\"Failed to load BuniAI widget script\"));\n };\n\n document.head.appendChild(script);\n });\n }\n\n private initializeWidgetAPI(): void {\n // Set up communication with the loaded widget\n if (window.BuniChat) {\n // Configure the widget with our options\n window.BuniChat.configure(this.options.config || {});\n\n // Set up event forwarding from the widget to our event system\n window.BuniChat.on(\"visibility_changed\", (data: any) => {\n this.state.isOpen = data.visibility === \"visible\";\n this.emit(\"visibility_changed\", data);\n\n if (this.options.onVisibilityChanged) {\n this.options.onVisibilityChanged(data);\n }\n });\n\n window.BuniChat.on(\"new_message\", (data: any) => {\n if (data.isFromBot) {\n this.state.unreadCount++;\n }\n this.emit(\"new_message\", data);\n\n if (this.options.onNewMessage) {\n this.options.onNewMessage(data);\n }\n });\n\n window.BuniChat.on(\"minimized\", (data: any) => {\n this.state.isMinimized = true;\n this.emit(\"minimized\", data);\n });\n\n window.BuniChat.on(\"maximized\", (data: any) => {\n this.state.isMinimized = false;\n this.emit(\"maximized\", data);\n });\n }\n }\n\n private getBaseUrl(): string {\n // Return the base URL for the BuniAI platform\n return (globalThis as any).BUNI_API_URL || window.location.origin;\n }\n\n destroy(): void {\n if (window.BuniChat) {\n window.BuniChat.destroy();\n }\n\n if (this.widgetElement) {\n this.widgetElement.remove();\n this.widgetElement = null;\n }\n\n this.eventListeners.clear();\n this.state.isLoaded = false;\n this.customerData = null;\n this.sessionVariables = null;\n }\n\n show(): void {\n if (window.BuniChat) {\n window.BuniChat.show();\n }\n this.state.isOpen = true;\n this.state.unreadCount = 0;\n this.emit(\"visibility_changed\", { visibility: \"visible\" });\n }\n\n hide(): void {\n if (window.BuniChat) {\n window.BuniChat.hide();\n }\n this.state.isOpen = false;\n this.emit(\"visibility_changed\", { visibility: \"hidden\" });\n }\n\n toggle(): void {\n this.state.isOpen ? this.hide() : this.show();\n }\n\n minimize(): void {\n if (window.BuniChat) {\n window.BuniChat.minimize();\n }\n this.state.isMinimized = true;\n this.emit(\"minimized\", { timestamp: Date.now() });\n }\n\n maximize(): void {\n if (window.BuniChat) {\n window.BuniChat.maximize();\n }\n this.state.isMinimized = false;\n this.emit(\"maximized\", { timestamp: Date.now() });\n }\n\n setCustomerData(data: CustomerData): void {\n this.customerData = { ...this.customerData, ...data };\n\n if (window.BuniChat) {\n window.BuniChat.setCustomerData(this.customerData);\n }\n\n this.emit(\"customer_data_updated\", { data: this.customerData });\n }\n\n getCustomerData(): CustomerData | null {\n return this.customerData ? { ...this.customerData } : null;\n }\n\n setSessionVariables(variables: SessionVariables): void {\n this.sessionVariables = { ...this.sessionVariables, ...variables };\n\n if (window.BuniChat) {\n window.BuniChat.setSessionVariables(this.sessionVariables);\n }\n\n this.emit(\"session_updated\", { variables: this.sessionVariables });\n }\n\n getSessionVariables(): SessionVariables | null {\n return this.sessionVariables ? { ...this.sessionVariables } : null;\n }\n\n sendMessage(message: string): void {\n if (window.BuniChat) {\n window.BuniChat.sendMessage(message);\n }\n\n const messageData = {\n message,\n isFromBot: false,\n timestamp: Date.now(),\n messageId: `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,\n };\n\n this.emit(\"new_message\", messageData);\n }\n\n clearChat(): void {\n if (window.BuniChat) {\n window.BuniChat.clearChat();\n }\n this.state.unreadCount = 0;\n }\n\n on(event: string, callback: Function): void {\n if (!this.eventListeners.has(event)) {\n this.eventListeners.set(event, []);\n }\n this.eventListeners.get(event)!.push(callback);\n }\n\n off(event: string, callback?: Function): void {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n\n if (callback) {\n const index = listeners.indexOf(callback);\n if (index > -1) {\n listeners.splice(index, 1);\n }\n } else {\n this.eventListeners.set(event, []);\n }\n }\n\n emit(event: string, data?: any): void {\n const listeners = this.eventListeners.get(event);\n if (listeners) {\n listeners.forEach((callback) => {\n try {\n callback(data);\n } catch (error) {\n console.error(`Error in event listener for ${event}:`, error);\n }\n });\n }\n }\n\n getState(): BuniChatState {\n return { ...this.state };\n }\n\n isReady(): boolean {\n return this.state.isLoaded;\n }\n}\n\n// Utility function - named export\nexport function createBuniChatWidget(options: BuniChatOptions): BuniChatWidget {\n const widget = new BuniChatWidget();\n widget.initialize(options);\n return widget;\n}\n\n// Default export - the main widget class\nexport default BuniChatWidget;\n\n// Global type declaration for the widget API\ndeclare global {\n interface Window {\n BuniChat?: {\n configure: (config: any) => void;\n show: () => void;\n hide: () => void;\n minimize: () => void;\n maximize: () => void;\n destroy: () => void;\n setCustomerData: (data: CustomerData) => void;\n setSessionVariables: (variables: SessionVariables) => void;\n sendMessage: (message: string) => void;\n clearChat: () => void;\n on: (event: string, callback: Function) => void;\n off: (event: string, callback?: Function) => void;\n };\n }\n}\n","// Main exports for @buni.ai/chatbot-core\n\n// Export all types\nexport * from \"./types\";\n\n// Export everything from widget\nexport * from \"./widget\";\n\n// Make B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C;AACzC,YAAA,IAAI,KAAK,GAAG,EAAE,EAAE;AACd,gBAAA,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;YAC5B;QACF;aAAO;YACL,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC;QACpC;IACF;IAEA,IAAI,CAAC,KAAa,EAAE,IAAU,EAAA;QAC5B,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC;QAChD,IAAI,SAAS,EAAE;AACb,YAAA,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,KAAI;AAC7B,gBAAA,IAAI;oBACF,QAAQ,CAAC,IAAI,CAAC;gBAChB;gBAAE,OAAO,KAAK,EAAE;oBACd,OAAO,CAAC,KAAK,CAAC,CAAA,4BAAA,EAA+B,KAAK,CAAA,CAAA,CAAG,EAAE,KAAK,CAAC;gBAC/D;AACF,YAAA,CAAC,CAAC;QACJ;IACF;IAEA,QAAQ,GAAA;AACN,QAAA,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE;IAC1B;IAEA,OAAO,GAAA;AACL,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ;IAC5B;AACD;AAED;AACM,SAAU,oBAAoB,CAAC,OAAwB,EAAA;AAC3D,IAAA,MAAM,MAAM,GAAG,IAAI,cAAc,EAAE;AACnC,IAAA,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC;AAC1B,IAAA,OAAO,MAAM;AACf;;ACnRA;AAEA;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/widget.ts","../src/index.ts"],"sourcesContent":["import {\n BuniChatAPI,\n BuniChatOptions,\n BuniChatState,\n CustomerData,\n SessionVariables,\n} from \"./types\";\n\n// Core widget loader class\nexport class BuniChatWidget implements BuniChatAPI {\n private options!: BuniChatOptions;\n private state: BuniChatState;\n private eventListeners: Map<string, Function[]>;\n private widgetElement: HTMLElement | null;\n private customerData: CustomerData | null;\n private sessionVariables: SessionVariables | null;\n\n constructor() {\n this.state = {\n isOpen: false,\n isLoaded: false,\n isMinimized: false,\n unreadCount: 0,\n };\n this.eventListeners = new Map();\n this.widgetElement = null;\n this.customerData = null;\n this.sessionVariables = null;\n }\n\n async initialize(options: BuniChatOptions): Promise<void> {\n this.options = options;\n\n try {\n await this.loadWidget();\n this.state.isLoaded = true;\n this.emit(\"ready\", { timestamp: Date.now() });\n\n if (options.onReady) {\n options.onReady({ timestamp: Date.now() });\n }\n } catch (error) {\n const errorObj =\n error instanceof Error ? error : new Error(String(error));\n this.emit(\"error\", { error: errorObj, context: \"initialization\" });\n\n if (options.onError) {\n options.onError(errorObj);\n }\n throw errorObj;\n }\n }\n\n private async loadWidget(): Promise<void> {\n return new Promise((resolve, reject) => {\n // Create container div for proper positioning\n const container = document.createElement(\"div\");\n container.id = \"buni-chat-widget-container\";\n const config = this.options.config || {};\n \n container.style.cssText = `\n position: fixed;\n pointer-events: none;\n z-index: 999999;\n ${this.getPositionStyles(config.position || \"bottom-right\")}\n display: ${config.hideDefaultTrigger ? \"none\" : \"block\"};\n `;\n\n // Create iframe for secure embedding\n const iframe = document.createElement(\"iframe\");\n\n // Build URL with configuration parameters\n const params = new URLSearchParams({\n token: this.options.token,\n embedded: \"true\",\n theme: config.theme || \"light\",\n width: String(config.width || \"350px\"),\n height: String(config.height || \"650px\"),\n primaryColor: config.primaryColor || \"#795548\",\n secondaryColor: config.secondaryColor || \"#A67D67\",\n position: config.position || \"bottom-right\",\n showBranding: String(config.showBranding !== false),\n autoOpen: String(config.autoOpen === true),\n minimized: String(config.minimized === true),\n allowMinimize: String(config.allowMinimize !== false),\n showMinimize: String(config.showMinimize !== false),\n enableFileUpload: String(config.enableFileUpload === true),\n });\n\n // Add optional parameters\n if (config.customAvatar) params.set(\"customAvatar\", config.customAvatar);\n if (config.companyName) params.set(\"companyName\", config.companyName);\n if (config.welcomeMessage)\n params.set(\"welcomeMessage\", config.welcomeMessage);\n if (config.triggerText) params.set(\"triggerText\", config.triggerText);\n if (config.borderRadius) params.set(\"borderRadius\", config.borderRadius);\n\n iframe.src = `${this.getBaseUrl()}/embed/chat?${params.toString()}`;\n iframe.style.cssText = `\n position: relative;\n border: none;\n width: ${config.width || \"350px\"};\n height: ${config.height || \"650px\"};\n border-radius: 12px;\n transition: all 0.3s ease;\n pointer-events: auto;\n box-shadow: 0 4px 12px rgba(0,0,0,0.15);\n `;\n iframe.setAttribute(\"allow\", \"clipboard-write\");\n iframe.setAttribute(\"title\", \"BuniAI Chat Widget\");\n\n iframe.onload = () => {\n this.widgetElement = container;\n this.setupPostMessageAPI(iframe);\n resolve();\n };\n\n iframe.onerror = () => {\n reject(new Error(\"Failed to load BuniAI widget iframe\"));\n };\n\n container.appendChild(iframe);\n document.body.appendChild(container);\n });\n }\n\n private getPositionStyles(position: string): string {\n switch (position) {\n case \"bottom-right\":\n return \"bottom: 20px; right: 20px;\";\n case \"bottom-left\":\n return \"bottom: 20px; left: 20px;\";\n case \"top-right\":\n return \"top: 20px; right: 20px;\";\n case \"top-left\":\n return \"top: 20px; left: 20px;\";\n default:\n return \"bottom: 20px; right: 20px;\";\n }\n }\n\n private setupPostMessageAPI(iframe: HTMLIFrameElement): void {\n // Listen for messages from the iframe\n window.addEventListener(\"message\", (event) => {\n // Verify origin for security\n if (event.origin !== this.getBaseUrl()) {\n return;\n }\n\n const { type, data } = event.data;\n\n switch (type) {\n case \"ready\":\n this.state.isLoaded = true;\n this.emit(\"ready\", data);\n if (this.options.onReady) {\n this.options.onReady(data);\n }\n break;\n\n case \"visibility_changed\":\n this.state.isOpen = data.visibility === \"visible\";\n this.emit(\"visibility_changed\", data);\n if (this.options.onVisibilityChanged) {\n this.options.onVisibilityChanged(data);\n }\n break;\n\n case \"new_message\":\n if (data.isFromBot) {\n this.state.unreadCount++;\n }\n this.emit(\"new_message\", data);\n if (this.options.onNewMessage) {\n this.options.onNewMessage(data);\n }\n break;\n\n case \"minimized\":\n this.state.isMinimized = true;\n this.emit(\"minimized\", data);\n break;\n\n case \"maximized\":\n this.state.isMinimized = false;\n this.emit(\"maximized\", data);\n break;\n\n case \"customer_data_updated\":\n this.customerData = data;\n this.emit(\"customer_data_updated\", data);\n break;\n\n case \"session_updated\":\n this.sessionVariables = data.variables;\n this.emit(\"session_updated\", data);\n break;\n\n case \"error\":\n this.emit(\"error\", data);\n if (this.options.onError) {\n this.options.onError(data.error);\n }\n break;\n }\n });\n }\n\n private postMessageToWidget(type: string, data?: any): void {\n if (this.widgetElement && this.widgetElement instanceof HTMLIFrameElement) {\n this.widgetElement.contentWindow?.postMessage(\n { type, data },\n this.getBaseUrl()\n );\n }\n }\n\n private initializeWidgetAPI(): void {\n // Widget API is now handled via postMessage in setupPostMessageAPI\n // This method is kept for backward compatibility but no longer needed\n }\n\n private getBaseUrl(): string {\n // Return the base URL for the BuniAI platform\n return (globalThis as any).BUNI_API_URL || window.location.origin;\n }\n\n destroy(): void {\n this.postMessageToWidget(\"destroy\");\n\n if (this.widgetElement) {\n this.widgetElement.remove();\n this.widgetElement = null;\n }\n\n this.eventListeners.clear();\n this.state.isLoaded = false;\n this.customerData = null;\n this.sessionVariables = null;\n }\n\n show(): void {\n // Show the iframe if it was hidden (hideDefaultTrigger mode)\n if (this.widgetElement instanceof HTMLIFrameElement) {\n this.widgetElement.style.display = \"block\";\n }\n this.postMessageToWidget(\"show\");\n this.state.isOpen = true;\n this.state.unreadCount = 0;\n this.emit(\"visibility_changed\", { visibility: \"visible\" });\n }\n\n hide(): void {\n this.postMessageToWidget(\"hide\");\n // If hideDefaultTrigger is enabled, completely hide the iframe\n if (this.options.config?.hideDefaultTrigger && this.widgetElement instanceof HTMLIFrameElement) {\n this.widgetElement.style.display = \"none\";\n }\n this.state.isOpen = false;\n this.emit(\"visibility_changed\", { visibility: \"hidden\" });\n }\n\n toggle(): void {\n this.state.isOpen ? this.hide() : this.show();\n }\n\n minimize(): void {\n this.postMessageToWidget(\"minimize\");\n this.state.isMinimized = true;\n this.emit(\"minimized\", { timestamp: Date.now() });\n }\n\n maximize(): void {\n this.postMessageToWidget(\"maximize\");\n this.state.isMinimized = false;\n this.emit(\"maximized\", { timestamp: Date.now() });\n }\n\n setCustomerData(data: CustomerData): void {\n this.customerData = { ...this.customerData, ...data };\n this.postMessageToWidget(\"setCustomerData\", this.customerData);\n this.emit(\"customer_data_updated\", { data: this.customerData });\n }\n\n getCustomerData(): CustomerData | null {\n return this.customerData ? { ...this.customerData } : null;\n }\n\n setSessionVariables(variables: SessionVariables): void {\n this.sessionVariables = { ...this.sessionVariables, ...variables };\n this.postMessageToWidget(\"setSessionVariables\", this.sessionVariables);\n this.emit(\"session_updated\", { variables: this.sessionVariables });\n }\n\n getSessionVariables(): SessionVariables | null {\n return this.sessionVariables ? { ...this.sessionVariables } : null;\n }\n\n sendMessage(message: string): void {\n this.postMessageToWidget(\"sendMessage\", { message });\n\n const messageData = {\n message,\n isFromBot: false,\n timestamp: Date.now(),\n messageId: `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,\n };\n\n this.emit(\"new_message\", messageData);\n }\n\n clearChat(): void {\n this.postMessageToWidget(\"clearChat\");\n this.state.unreadCount = 0;\n }\n\n on(event: string, callback: Function): void {\n if (!this.eventListeners.has(event)) {\n this.eventListeners.set(event, []);\n }\n this.eventListeners.get(event)!.push(callback);\n }\n\n off(event: string, callback?: Function): void {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n\n if (callback) {\n const index = listeners.indexOf(callback);\n if (index > -1) {\n listeners.splice(index, 1);\n }\n } else {\n this.eventListeners.set(event, []);\n }\n }\n\n emit(event: string, data?: any): void {\n const listeners = this.eventListeners.get(event);\n if (listeners) {\n listeners.forEach((callback) => {\n try {\n callback(data);\n } catch (error) {\n console.error(`Error in event listener for ${event}:`, error);\n }\n });\n }\n }\n\n getState(): BuniChatState {\n return { ...this.state };\n }\n\n isReady(): boolean {\n return this.state.isLoaded;\n }\n}\n\n// Utility function - named export\nexport function createBuniChatWidget(options: BuniChatOptions): BuniChatWidget {\n const widget = new BuniChatWidget();\n widget.initialize(options);\n return widget;\n}\n\n// Default export - the main widget class\nexport default BuniChatWidget;\n\n// Global type declaration for the widget API\ndeclare global {\n interface Window {\n BuniChat?: {\n configure: (config: any) => void;\n show: () => void;\n hide: () => void;\n minimize: () => void;\n maximize: () => void;\n destroy: () => void;\n setCustomerData: (data: CustomerData) => void;\n setSessionVariables: (variables: SessionVariables) => void;\n sendMessage: (message: string) => void;\n clearChat: () => void;\n on: (event: string, callback: Function) => void;\n off: (event: string, callback?: Function) => void;\n };\n }\n}\n","// Main exports for @buni.ai/chatbot-core\n\n// Export all types\nexport * from \"./types\";\n\n// Export everything from widget\nexport * from \"./widget\";\n\n// Make BuniChatWidget the default export as well\nimport { BuniChatWidget } from \"./widget\";\nexport default BuniChatWidget;\n"],"names":[],"mappings":"AAQA;MACa,cAAc,CAAA;AAQzB,IAAA,WAAA,GAAA;QACE,IAAI,CAAC,KAAK,GAAG;AACX,YAAA,MAAM,EAAE,KAAK;AACb,YAAA,QAAQ,EAAE,KAAK;AACf,YAAA,WAAW,EAAE,KAAK;AAClB,YAAA,WAAW,EAAE,CAAC;SACf,CAAC;AACF,QAAA,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;AAChC,QAAA,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;AAC1B,QAAA,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;AACzB,QAAA,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;KAC9B;IAED,MAAM,UAAU,CAAC,OAAwB,EAAA;AACvC,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;AAEvB,QAAA,IAAI;AACF,YAAA,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;AACxB,YAAA,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;AAC3B,YAAA,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAA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,CAAC;iBAChB;gBAAC,OAAO,KAAK,EAAE;oBACd,OAAO,CAAC,KAAK,CAAC,CAAA,4BAAA,EAA+B,KAAK,CAAG,CAAA,CAAA,EAAE,KAAK,CAAC,CAAC;iBAC/D;AACH,aAAC,CAAC,CAAC;SACJ;KACF;IAED,QAAQ,GAAA;AACN,QAAA,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;KAC1B;IAED,OAAO,GAAA;AACL,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;KAC5B;AACF,CAAA;AAED;AACM,SAAU,oBAAoB,CAAC,OAAwB,EAAA;AAC3D,IAAA,MAAM,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;AACpC,IAAA,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC3B,IAAA,OAAO,MAAM,CAAC;AAChB;;AC5WA;AAEA;;;;"}
package/dist/index.js CHANGED
@@ -37,66 +37,159 @@ class BuniChatWidget {
37
37
  }
38
38
  async loadWidget() {
39
39
  return new Promise((resolve, reject) => {
40
- // Check if widget is already loaded
41
- if (window.BuniChat) {
42
- resolve();
43
- return;
44
- }
45
- // Load the widget script dynamically
46
- const script = document.createElement("script");
47
- script.src = `${this.getBaseUrl()}/api/embed/widget?token=${encodeURIComponent(this.options.token)}`;
48
- script.async = true;
49
- script.onload = () => {
50
- // Initialize the actual widget
51
- this.initializeWidgetAPI();
40
+ // Create container div for proper positioning
41
+ const container = document.createElement("div");
42
+ container.id = "buni-chat-widget-container";
43
+ const config = this.options.config || {};
44
+ container.style.cssText = `
45
+ position: fixed;
46
+ pointer-events: none;
47
+ z-index: 999999;
48
+ ${this.getPositionStyles(config.position || "bottom-right")}
49
+ display: ${config.hideDefaultTrigger ? "none" : "block"};
50
+ `;
51
+ // Create iframe for secure embedding
52
+ const iframe = document.createElement("iframe");
53
+ // Build URL with configuration parameters
54
+ const params = new URLSearchParams({
55
+ token: this.options.token,
56
+ embedded: "true",
57
+ theme: config.theme || "light",
58
+ width: String(config.width || "350px"),
59
+ height: String(config.height || "650px"),
60
+ primaryColor: config.primaryColor || "#795548",
61
+ secondaryColor: config.secondaryColor || "#A67D67",
62
+ position: config.position || "bottom-right",
63
+ showBranding: String(config.showBranding !== false),
64
+ autoOpen: String(config.autoOpen === true),
65
+ minimized: String(config.minimized === true),
66
+ allowMinimize: String(config.allowMinimize !== false),
67
+ showMinimize: String(config.showMinimize !== false),
68
+ enableFileUpload: String(config.enableFileUpload === true),
69
+ });
70
+ // Add optional parameters
71
+ if (config.customAvatar)
72
+ params.set("customAvatar", config.customAvatar);
73
+ if (config.companyName)
74
+ params.set("companyName", config.companyName);
75
+ if (config.welcomeMessage)
76
+ params.set("welcomeMessage", config.welcomeMessage);
77
+ if (config.triggerText)
78
+ params.set("triggerText", config.triggerText);
79
+ if (config.borderRadius)
80
+ params.set("borderRadius", config.borderRadius);
81
+ iframe.src = `${this.getBaseUrl()}/embed/chat?${params.toString()}`;
82
+ iframe.style.cssText = `
83
+ position: relative;
84
+ border: none;
85
+ width: ${config.width || "350px"};
86
+ height: ${config.height || "650px"};
87
+ border-radius: 12px;
88
+ transition: all 0.3s ease;
89
+ pointer-events: auto;
90
+ box-shadow: 0 4px 12px rgba(0,0,0,0.15);
91
+ `;
92
+ iframe.setAttribute("allow", "clipboard-write");
93
+ iframe.setAttribute("title", "BuniAI Chat Widget");
94
+ iframe.onload = () => {
95
+ this.widgetElement = container;
96
+ this.setupPostMessageAPI(iframe);
52
97
  resolve();
53
98
  };
54
- script.onerror = () => {
55
- reject(new Error("Failed to load BuniAI widget script"));
99
+ iframe.onerror = () => {
100
+ reject(new Error("Failed to load BuniAI widget iframe"));
56
101
  };
57
- document.head.appendChild(script);
102
+ container.appendChild(iframe);
103
+ document.body.appendChild(container);
58
104
  });
59
105
  }
60
- initializeWidgetAPI() {
61
- // Set up communication with the loaded widget
62
- if (window.BuniChat) {
63
- // Configure the widget with our options
64
- window.BuniChat.configure(this.options.config || {});
65
- // Set up event forwarding from the widget to our event system
66
- window.BuniChat.on("visibility_changed", (data) => {
67
- this.state.isOpen = data.visibility === "visible";
68
- this.emit("visibility_changed", data);
69
- if (this.options.onVisibilityChanged) {
70
- this.options.onVisibilityChanged(data);
71
- }
72
- });
73
- window.BuniChat.on("new_message", (data) => {
74
- if (data.isFromBot) {
75
- this.state.unreadCount++;
76
- }
77
- this.emit("new_message", data);
78
- if (this.options.onNewMessage) {
79
- this.options.onNewMessage(data);
80
- }
81
- });
82
- window.BuniChat.on("minimized", (data) => {
83
- this.state.isMinimized = true;
84
- this.emit("minimized", data);
85
- });
86
- window.BuniChat.on("maximized", (data) => {
87
- this.state.isMinimized = false;
88
- this.emit("maximized", data);
89
- });
106
+ getPositionStyles(position) {
107
+ switch (position) {
108
+ case "bottom-right":
109
+ return "bottom: 20px; right: 20px;";
110
+ case "bottom-left":
111
+ return "bottom: 20px; left: 20px;";
112
+ case "top-right":
113
+ return "top: 20px; right: 20px;";
114
+ case "top-left":
115
+ return "top: 20px; left: 20px;";
116
+ default:
117
+ return "bottom: 20px; right: 20px;";
118
+ }
119
+ }
120
+ setupPostMessageAPI(iframe) {
121
+ // Listen for messages from the iframe
122
+ window.addEventListener("message", (event) => {
123
+ // Verify origin for security
124
+ if (event.origin !== this.getBaseUrl()) {
125
+ return;
126
+ }
127
+ const { type, data } = event.data;
128
+ switch (type) {
129
+ case "ready":
130
+ this.state.isLoaded = true;
131
+ this.emit("ready", data);
132
+ if (this.options.onReady) {
133
+ this.options.onReady(data);
134
+ }
135
+ break;
136
+ case "visibility_changed":
137
+ this.state.isOpen = data.visibility === "visible";
138
+ this.emit("visibility_changed", data);
139
+ if (this.options.onVisibilityChanged) {
140
+ this.options.onVisibilityChanged(data);
141
+ }
142
+ break;
143
+ case "new_message":
144
+ if (data.isFromBot) {
145
+ this.state.unreadCount++;
146
+ }
147
+ this.emit("new_message", data);
148
+ if (this.options.onNewMessage) {
149
+ this.options.onNewMessage(data);
150
+ }
151
+ break;
152
+ case "minimized":
153
+ this.state.isMinimized = true;
154
+ this.emit("minimized", data);
155
+ break;
156
+ case "maximized":
157
+ this.state.isMinimized = false;
158
+ this.emit("maximized", data);
159
+ break;
160
+ case "customer_data_updated":
161
+ this.customerData = data;
162
+ this.emit("customer_data_updated", data);
163
+ break;
164
+ case "session_updated":
165
+ this.sessionVariables = data.variables;
166
+ this.emit("session_updated", data);
167
+ break;
168
+ case "error":
169
+ this.emit("error", data);
170
+ if (this.options.onError) {
171
+ this.options.onError(data.error);
172
+ }
173
+ break;
174
+ }
175
+ });
176
+ }
177
+ postMessageToWidget(type, data) {
178
+ var _a;
179
+ if (this.widgetElement && this.widgetElement instanceof HTMLIFrameElement) {
180
+ (_a = this.widgetElement.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage({ type, data }, this.getBaseUrl());
90
181
  }
91
182
  }
183
+ initializeWidgetAPI() {
184
+ // Widget API is now handled via postMessage in setupPostMessageAPI
185
+ // This method is kept for backward compatibility but no longer needed
186
+ }
92
187
  getBaseUrl() {
93
188
  // Return the base URL for the BuniAI platform
94
189
  return globalThis.BUNI_API_URL || window.location.origin;
95
190
  }
96
191
  destroy() {
97
- if (window.BuniChat) {
98
- window.BuniChat.destroy();
99
- }
192
+ this.postMessageToWidget("destroy");
100
193
  if (this.widgetElement) {
101
194
  this.widgetElement.remove();
102
195
  this.widgetElement = null;
@@ -107,16 +200,21 @@ class BuniChatWidget {
107
200
  this.sessionVariables = null;
108
201
  }
109
202
  show() {
110
- if (window.BuniChat) {
111
- window.BuniChat.show();
203
+ // Show the iframe if it was hidden (hideDefaultTrigger mode)
204
+ if (this.widgetElement instanceof HTMLIFrameElement) {
205
+ this.widgetElement.style.display = "block";
112
206
  }
207
+ this.postMessageToWidget("show");
113
208
  this.state.isOpen = true;
114
209
  this.state.unreadCount = 0;
115
210
  this.emit("visibility_changed", { visibility: "visible" });
116
211
  }
117
212
  hide() {
118
- if (window.BuniChat) {
119
- window.BuniChat.hide();
213
+ var _a;
214
+ this.postMessageToWidget("hide");
215
+ // If hideDefaultTrigger is enabled, completely hide the iframe
216
+ if (((_a = this.options.config) === null || _a === void 0 ? void 0 : _a.hideDefaultTrigger) && this.widgetElement instanceof HTMLIFrameElement) {
217
+ this.widgetElement.style.display = "none";
120
218
  }
121
219
  this.state.isOpen = false;
122
220
  this.emit("visibility_changed", { visibility: "hidden" });
@@ -125,24 +223,18 @@ class BuniChatWidget {
125
223
  this.state.isOpen ? this.hide() : this.show();
126
224
  }
127
225
  minimize() {
128
- if (window.BuniChat) {
129
- window.BuniChat.minimize();
130
- }
226
+ this.postMessageToWidget("minimize");
131
227
  this.state.isMinimized = true;
132
228
  this.emit("minimized", { timestamp: Date.now() });
133
229
  }
134
230
  maximize() {
135
- if (window.BuniChat) {
136
- window.BuniChat.maximize();
137
- }
231
+ this.postMessageToWidget("maximize");
138
232
  this.state.isMinimized = false;
139
233
  this.emit("maximized", { timestamp: Date.now() });
140
234
  }
141
235
  setCustomerData(data) {
142
236
  this.customerData = { ...this.customerData, ...data };
143
- if (window.BuniChat) {
144
- window.BuniChat.setCustomerData(this.customerData);
145
- }
237
+ this.postMessageToWidget("setCustomerData", this.customerData);
146
238
  this.emit("customer_data_updated", { data: this.customerData });
147
239
  }
148
240
  getCustomerData() {
@@ -150,18 +242,14 @@ class BuniChatWidget {
150
242
  }
151
243
  setSessionVariables(variables) {
152
244
  this.sessionVariables = { ...this.sessionVariables, ...variables };
153
- if (window.BuniChat) {
154
- window.BuniChat.setSessionVariables(this.sessionVariables);
155
- }
245
+ this.postMessageToWidget("setSessionVariables", this.sessionVariables);
156
246
  this.emit("session_updated", { variables: this.sessionVariables });
157
247
  }
158
248
  getSessionVariables() {
159
249
  return this.sessionVariables ? { ...this.sessionVariables } : null;
160
250
  }
161
251
  sendMessage(message) {
162
- if (window.BuniChat) {
163
- window.BuniChat.sendMessage(message);
164
- }
252
+ this.postMessageToWidget("sendMessage", { message });
165
253
  const messageData = {
166
254
  message,
167
255
  isFromBot: false,
@@ -171,9 +259,7 @@ class BuniChatWidget {
171
259
  this.emit("new_message", messageData);
172
260
  }
173
261
  clearChat() {
174
- if (window.BuniChat) {
175
- window.BuniChat.clearChat();
176
- }
262
+ this.postMessageToWidget("clearChat");
177
263
  this.state.unreadCount = 0;
178
264
  }
179
265
  on(event, callback) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/widget.ts","../src/index.ts"],"sourcesContent":["import {\n BuniChatAPI,\n BuniChatOptions,\n BuniChatState,\n CustomerData,\n SessionVariables,\n} from \"./types\";\n\n// Core widget loader class\nexport class BuniChatWidget implements BuniChatAPI {\n private options!: BuniChatOptions;\n private state: BuniChatState;\n private eventListeners: Map<string, Function[]>;\n private widgetElement: HTMLElement | null;\n private customerData: CustomerData | null;\n private sessionVariables: SessionVariables | null;\n\n constructor() {\n this.state = {\n isOpen: false,\n isLoaded: false,\n isMinimized: false,\n unreadCount: 0,\n };\n this.eventListeners = new Map();\n this.widgetElement = null;\n this.customerData = null;\n this.sessionVariables = null;\n }\n\n async initialize(options: BuniChatOptions): Promise<void> {\n this.options = options;\n\n try {\n await this.loadWidget();\n this.state.isLoaded = true;\n this.emit(\"ready\", { timestamp: Date.now() });\n\n if (options.onReady) {\n options.onReady({ timestamp: Date.now() });\n }\n } catch (error) {\n const errorObj =\n error instanceof Error ? error : new Error(String(error));\n this.emit(\"error\", { error: errorObj, context: \"initialization\" });\n\n if (options.onError) {\n options.onError(errorObj);\n }\n throw errorObj;\n }\n }\n\n private async loadWidget(): Promise<void> {\n return new Promise((resolve, reject) => {\n // Check if widget is already loaded\n if (window.BuniChat) {\n resolve();\n return;\n }\n\n // Load the widget script dynamically\n const script = document.createElement(\"script\");\n script.src = `${this.getBaseUrl()}/api/embed/widget?token=${encodeURIComponent(this.options.token)}`;\n script.async = true;\n\n script.onload = () => {\n // Initialize the actual widget\n this.initializeWidgetAPI();\n resolve();\n };\n\n script.onerror = () => {\n reject(new Error(\"Failed to load BuniAI widget script\"));\n };\n\n document.head.appendChild(script);\n });\n }\n\n private initializeWidgetAPI(): void {\n // Set up communication with the loaded widget\n if (window.BuniChat) {\n // Configure the widget with our options\n window.BuniChat.configure(this.options.config || {});\n\n // Set up event forwarding from the widget to our event system\n window.BuniChat.on(\"visibility_changed\", (data: any) => {\n this.state.isOpen = data.visibility === \"visible\";\n this.emit(\"visibility_changed\", data);\n\n if (this.options.onVisibilityChanged) {\n this.options.onVisibilityChanged(data);\n }\n });\n\n window.BuniChat.on(\"new_message\", (data: any) => {\n if (data.isFromBot) {\n this.state.unreadCount++;\n }\n this.emit(\"new_message\", data);\n\n if (this.options.onNewMessage) {\n this.options.onNewMessage(data);\n }\n });\n\n window.BuniChat.on(\"minimized\", (data: any) => {\n this.state.isMinimized = true;\n this.emit(\"minimized\", data);\n });\n\n window.BuniChat.on(\"maximized\", (data: any) => {\n this.state.isMinimized = false;\n this.emit(\"maximized\", data);\n });\n }\n }\n\n private getBaseUrl(): string {\n // Return the base URL for the BuniAI platform\n return (globalThis as any).BUNI_API_URL || window.location.origin;\n }\n\n destroy(): void {\n if (window.BuniChat) {\n window.BuniChat.destroy();\n }\n\n if (this.widgetElement) {\n this.widgetElement.remove();\n this.widgetElement = null;\n }\n\n this.eventListeners.clear();\n this.state.isLoaded = false;\n this.customerData = null;\n this.sessionVariables = null;\n }\n\n show(): void {\n if (window.BuniChat) {\n window.BuniChat.show();\n }\n this.state.isOpen = true;\n this.state.unreadCount = 0;\n this.emit(\"visibility_changed\", { visibility: \"visible\" });\n }\n\n hide(): void {\n if (window.BuniChat) {\n window.BuniChat.hide();\n }\n this.state.isOpen = false;\n this.emit(\"visibility_changed\", { visibility: \"hidden\" });\n }\n\n toggle(): void {\n this.state.isOpen ? this.hide() : this.show();\n }\n\n minimize(): void {\n if (window.BuniChat) {\n window.BuniChat.minimize();\n }\n this.state.isMinimized = true;\n this.emit(\"minimized\", { timestamp: Date.now() });\n }\n\n maximize(): void {\n if (window.BuniChat) {\n window.BuniChat.maximize();\n }\n this.state.isMinimized = false;\n this.emit(\"maximized\", { timestamp: Date.now() });\n }\n\n setCustomerData(data: CustomerData): void {\n this.customerData = { ...this.customerData, ...data };\n\n if (window.BuniChat) {\n window.BuniChat.setCustomerData(this.customerData);\n }\n\n this.emit(\"customer_data_updated\", { data: this.customerData });\n }\n\n getCustomerData(): CustomerData | null {\n return this.customerData ? { ...this.customerData } : null;\n }\n\n setSessionVariables(variables: SessionVariables): void {\n this.sessionVariables = { ...this.sessionVariables, ...variables };\n\n if (window.BuniChat) {\n window.BuniChat.setSessionVariables(this.sessionVariables);\n }\n\n this.emit(\"session_updated\", { variables: this.sessionVariables });\n }\n\n getSessionVariables(): SessionVariables | null {\n return this.sessionVariables ? { ...this.sessionVariables } : null;\n }\n\n sendMessage(message: string): void {\n if (window.BuniChat) {\n window.BuniChat.sendMessage(message);\n }\n\n const messageData = {\n message,\n isFromBot: false,\n timestamp: Date.now(),\n messageId: `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,\n };\n\n this.emit(\"new_message\", messageData);\n }\n\n clearChat(): void {\n if (window.BuniChat) {\n window.BuniChat.clearChat();\n }\n this.state.unreadCount = 0;\n }\n\n on(event: string, callback: Function): void {\n if (!this.eventListeners.has(event)) {\n this.eventListeners.set(event, []);\n }\n this.eventListeners.get(event)!.push(callback);\n }\n\n off(event: string, callback?: Function): void {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n\n if (callback) {\n const index = listeners.indexOf(callback);\n if (index > -1) {\n listeners.splice(index, 1);\n }\n } else {\n this.eventListeners.set(event, []);\n }\n }\n\n emit(event: string, data?: any): void {\n const listeners = this.eventListeners.get(event);\n if (listeners) {\n listeners.forEach((callback) => {\n try {\n callback(data);\n } catch (error) {\n console.error(`Error in event listener for ${event}:`, error);\n }\n });\n }\n }\n\n getState(): BuniChatState {\n return { ...this.state };\n }\n\n isReady(): boolean {\n return this.state.isLoaded;\n }\n}\n\n// Utility function - named export\nexport function createBuniChatWidget(options: BuniChatOptions): BuniChatWidget {\n const widget = new BuniChatWidget();\n widget.initialize(options);\n return widget;\n}\n\n// Default export - the main widget class\nexport default BuniChatWidget;\n\n// Global type declaration for the widget API\ndeclare global {\n interface Window {\n BuniChat?: {\n configure: (config: any) => void;\n show: () => void;\n hide: () => void;\n minimize: () => void;\n maximize: () => void;\n destroy: () => void;\n setCustomerData: (data: CustomerData) => void;\n setSessionVariables: (variables: SessionVariables) => void;\n sendMessage: (message: string) => void;\n clearChat: () => void;\n on: (event: string, callback: Function) => void;\n off: (event: string, callback?: Function) => void;\n };\n }\n}\n","// Main exports for @buni.ai/chatbot-core\n\n// Export all types\nexport * from \"./types\";\n\n// Export everything from widget\nexport * from \"./widget\";\n\n// Make BuniChatWidget the default export as well\nimport { BuniChatWidget } from \"./widget\";\nexport default BuniChatWidget;\n"],"names":[],"mappings":";;;;AAQA;MACa,cAAc,CAAA;AAQzB,IAAA,WAAA,GAAA;QACE,IAAI,CAAC,KAAK,GAAG;AACX,YAAA,MAAM,EAAE,KAAK;AACb,YAAA,QAAQ,EAAE,KAAK;AACf,YAAA,WAAW,EAAE,KAAK;AAClB,YAAA,WAAW,EAAE,CAAC;SACf;AACD,QAAA,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE;AAC/B,QAAA,IAAI,CAAC,aAAa,GAAG,IAAI;AACzB,QAAA,IAAI,CAAC,YAAY,GAAG,IAAI;AACxB,QAAA,IAAI,CAAC,gBAAgB,GAAG,IAAI;IAC9B;IAEA,MAAM,UAAU,CAAC,OAAwB,EAAA;AACvC,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;AAEtB,QAAA,IAAI;AACF,YAAA,MAAM,IAAI,CAAC,UAAU,EAAE;AACvB,YAAA,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI;AAC1B,YAAA,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AAE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;AAED;AACM,SAAU,oBAAoB,CAAC,OAAwB,EAAA;AAC3D,IAAA,MAAM,MAAM,GAAG,IAAI,cAAc,EAAE;AACnC,IAAA,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC;AAC1B,IAAA,OAAO,MAAM;AACf;;ACnRA;AAEA;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/widget.ts","../src/index.ts"],"sourcesContent":["import {\n BuniChatAPI,\n BuniChatOptions,\n BuniChatState,\n CustomerData,\n SessionVariables,\n} from \"./types\";\n\n// Core widget loader class\nexport class BuniChatWidget implements BuniChatAPI {\n private options!: BuniChatOptions;\n private state: BuniChatState;\n private eventListeners: Map<string, Function[]>;\n private widgetElement: HTMLElement | null;\n private customerData: CustomerData | null;\n private sessionVariables: SessionVariables | null;\n\n constructor() {\n this.state = {\n isOpen: false,\n isLoaded: false,\n isMinimized: false,\n unreadCount: 0,\n };\n this.eventListeners = new Map();\n this.widgetElement = null;\n this.customerData = null;\n this.sessionVariables = null;\n }\n\n async initialize(options: BuniChatOptions): Promise<void> {\n this.options = options;\n\n try {\n await this.loadWidget();\n this.state.isLoaded = true;\n this.emit(\"ready\", { timestamp: Date.now() });\n\n if (options.onReady) {\n options.onReady({ timestamp: Date.now() });\n }\n } catch (error) {\n const errorObj =\n error instanceof Error ? error : new Error(String(error));\n this.emit(\"error\", { error: errorObj, context: \"initialization\" });\n\n if (options.onError) {\n options.onError(errorObj);\n }\n throw errorObj;\n }\n }\n\n private async loadWidget(): Promise<void> {\n return new Promise((resolve, reject) => {\n // Create container div for proper positioning\n const container = document.createElement(\"div\");\n container.id = \"buni-chat-widget-container\";\n const config = this.options.config || {};\n \n container.style.cssText = `\n position: fixed;\n pointer-events: none;\n z-index: 999999;\n ${this.getPositionStyles(config.position || \"bottom-right\")}\n display: ${config.hideDefaultTrigger ? \"none\" : \"block\"};\n `;\n\n // Create iframe for secure embedding\n const iframe = document.createElement(\"iframe\");\n\n // Build URL with configuration parameters\n const params = new URLSearchParams({\n token: this.options.token,\n embedded: \"true\",\n theme: config.theme || \"light\",\n width: String(config.width || \"350px\"),\n height: String(config.height || \"650px\"),\n primaryColor: config.primaryColor || \"#795548\",\n secondaryColor: config.secondaryColor || \"#A67D67\",\n position: config.position || \"bottom-right\",\n showBranding: String(config.showBranding !== false),\n autoOpen: String(config.autoOpen === true),\n minimized: String(config.minimized === true),\n allowMinimize: String(config.allowMinimize !== false),\n showMinimize: String(config.showMinimize !== false),\n enableFileUpload: String(config.enableFileUpload === true),\n });\n\n // Add optional parameters\n if (config.customAvatar) params.set(\"customAvatar\", config.customAvatar);\n if (config.companyName) params.set(\"companyName\", config.companyName);\n if (config.welcomeMessage)\n params.set(\"welcomeMessage\", config.welcomeMessage);\n if (config.triggerText) params.set(\"triggerText\", config.triggerText);\n if (config.borderRadius) params.set(\"borderRadius\", config.borderRadius);\n\n iframe.src = `${this.getBaseUrl()}/embed/chat?${params.toString()}`;\n iframe.style.cssText = `\n position: relative;\n border: none;\n width: ${config.width || \"350px\"};\n height: ${config.height || \"650px\"};\n border-radius: 12px;\n transition: all 0.3s ease;\n pointer-events: auto;\n box-shadow: 0 4px 12px rgba(0,0,0,0.15);\n `;\n iframe.setAttribute(\"allow\", \"clipboard-write\");\n iframe.setAttribute(\"title\", \"BuniAI Chat Widget\");\n\n iframe.onload = () => {\n this.widgetElement = container;\n this.setupPostMessageAPI(iframe);\n resolve();\n };\n\n iframe.onerror = () => {\n reject(new Error(\"Failed to load BuniAI widget iframe\"));\n };\n\n container.appendChild(iframe);\n document.body.appendChild(container);\n });\n }\n\n private getPositionStyles(position: string): string {\n switch (position) {\n case \"bottom-right\":\n return \"bottom: 20px; right: 20px;\";\n case \"bottom-left\":\n return \"bottom: 20px; left: 20px;\";\n case \"top-right\":\n return \"top: 20px; right: 20px;\";\n case \"top-left\":\n return \"top: 20px; left: 20px;\";\n default:\n return \"bottom: 20px; right: 20px;\";\n }\n }\n\n private setupPostMessageAPI(iframe: HTMLIFrameElement): void {\n // Listen for messages from the iframe\n window.addEventListener(\"message\", (event) => {\n // Verify origin for security\n if (event.origin !== this.getBaseUrl()) {\n return;\n }\n\n const { type, data } = event.data;\n\n switch (type) {\n case \"ready\":\n this.state.isLoaded = true;\n this.emit(\"ready\", data);\n if (this.options.onReady) {\n this.options.onReady(data);\n }\n break;\n\n case \"visibility_changed\":\n this.state.isOpen = data.visibility === \"visible\";\n this.emit(\"visibility_changed\", data);\n if (this.options.onVisibilityChanged) {\n this.options.onVisibilityChanged(data);\n }\n break;\n\n case \"new_message\":\n if (data.isFromBot) {\n this.state.unreadCount++;\n }\n this.emit(\"new_message\", data);\n if (this.options.onNewMessage) {\n this.options.onNewMessage(data);\n }\n break;\n\n case \"minimized\":\n this.state.isMinimized = true;\n this.emit(\"minimized\", data);\n break;\n\n case \"maximized\":\n this.state.isMinimized = false;\n this.emit(\"maximized\", data);\n break;\n\n case \"customer_data_updated\":\n this.customerData = data;\n this.emit(\"customer_data_updated\", data);\n break;\n\n case \"session_updated\":\n this.sessionVariables = data.variables;\n this.emit(\"session_updated\", data);\n break;\n\n case \"error\":\n this.emit(\"error\", data);\n if (this.options.onError) {\n this.options.onError(data.error);\n }\n break;\n }\n });\n }\n\n private postMessageToWidget(type: string, data?: any): void {\n if (this.widgetElement && this.widgetElement instanceof HTMLIFrameElement) {\n this.widgetElement.contentWindow?.postMessage(\n { type, data },\n this.getBaseUrl()\n );\n }\n }\n\n private initializeWidgetAPI(): void {\n // Widget API is now handled via postMessage in setupPostMessageAPI\n // This method is kept for backward compatibility but no longer needed\n }\n\n private getBaseUrl(): string {\n // Return the base URL for the BuniAI platform\n return (globalThis as any).BUNI_API_URL || window.location.origin;\n }\n\n destroy(): void {\n this.postMessageToWidget(\"destroy\");\n\n if (this.widgetElement) {\n this.widgetElement.remove();\n this.widgetElement = null;\n }\n\n this.eventListeners.clear();\n this.state.isLoaded = false;\n this.customerData = null;\n this.sessionVariables = null;\n }\n\n show(): void {\n // Show the iframe if it was hidden (hideDefaultTrigger mode)\n if (this.widgetElement instanceof HTMLIFrameElement) {\n this.widgetElement.style.display = \"block\";\n }\n this.postMessageToWidget(\"show\");\n this.state.isOpen = true;\n this.state.unreadCount = 0;\n this.emit(\"visibility_changed\", { visibility: \"visible\" });\n }\n\n hide(): void {\n this.postMessageToWidget(\"hide\");\n // If hideDefaultTrigger is enabled, completely hide the iframe\n if (this.options.config?.hideDefaultTrigger && this.widgetElement instanceof HTMLIFrameElement) {\n this.widgetElement.style.display = \"none\";\n }\n this.state.isOpen = false;\n this.emit(\"visibility_changed\", { visibility: \"hidden\" });\n }\n\n toggle(): void {\n this.state.isOpen ? this.hide() : this.show();\n }\n\n minimize(): void {\n this.postMessageToWidget(\"minimize\");\n this.state.isMinimized = true;\n this.emit(\"minimized\", { timestamp: Date.now() });\n }\n\n maximize(): void {\n this.postMessageToWidget(\"maximize\");\n this.state.isMinimized = false;\n this.emit(\"maximized\", { timestamp: Date.now() });\n }\n\n setCustomerData(data: CustomerData): void {\n this.customerData = { ...this.customerData, ...data };\n this.postMessageToWidget(\"setCustomerData\", this.customerData);\n this.emit(\"customer_data_updated\", { data: this.customerData });\n }\n\n getCustomerData(): CustomerData | null {\n return this.customerData ? { ...this.customerData } : null;\n }\n\n setSessionVariables(variables: SessionVariables): void {\n this.sessionVariables = { ...this.sessionVariables, ...variables };\n this.postMessageToWidget(\"setSessionVariables\", this.sessionVariables);\n this.emit(\"session_updated\", { variables: this.sessionVariables });\n }\n\n getSessionVariables(): SessionVariables | null {\n return this.sessionVariables ? { ...this.sessionVariables } : null;\n }\n\n sendMessage(message: string): void {\n this.postMessageToWidget(\"sendMessage\", { message });\n\n const messageData = {\n message,\n isFromBot: false,\n timestamp: Date.now(),\n messageId: `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,\n };\n\n this.emit(\"new_message\", messageData);\n }\n\n clearChat(): void {\n this.postMessageToWidget(\"clearChat\");\n this.state.unreadCount = 0;\n }\n\n on(event: string, callback: Function): void {\n if (!this.eventListeners.has(event)) {\n this.eventListeners.set(event, []);\n }\n this.eventListeners.get(event)!.push(callback);\n }\n\n off(event: string, callback?: Function): void {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n\n if (callback) {\n const index = listeners.indexOf(callback);\n if (index > -1) {\n listeners.splice(index, 1);\n }\n } else {\n this.eventListeners.set(event, []);\n }\n }\n\n emit(event: string, data?: any): void {\n const listeners = this.eventListeners.get(event);\n if (listeners) {\n listeners.forEach((callback) => {\n try {\n callback(data);\n } catch (error) {\n console.error(`Error in event listener for ${event}:`, error);\n }\n });\n }\n }\n\n getState(): BuniChatState {\n return { ...this.state };\n }\n\n isReady(): boolean {\n return this.state.isLoaded;\n }\n}\n\n// Utility function - named export\nexport function createBuniChatWidget(options: BuniChatOptions): BuniChatWidget {\n const widget = new BuniChatWidget();\n widget.initialize(options);\n return widget;\n}\n\n// Default export - the main widget class\nexport default BuniChatWidget;\n\n// Global type declaration for the widget API\ndeclare global {\n interface Window {\n BuniChat?: {\n configure: (config: any) => void;\n show: () => void;\n hide: () => void;\n minimize: () => void;\n maximize: () => void;\n destroy: () => void;\n setCustomerData: (data: CustomerData) => void;\n setSessionVariables: (variables: SessionVariables) => void;\n sendMessage: (message: string) => void;\n clearChat: () => void;\n on: (event: string, callback: Function) => void;\n off: (event: string, callback?: Function) => void;\n };\n }\n}\n","// Main exports for @buni.ai/chatbot-core\n\n// Export all types\nexport * from \"./types\";\n\n// Export everything from widget\nexport * from \"./widget\";\n\n// Make BuniChatWidget the default export as well\nimport { BuniChatWidget } from \"./widget\";\nexport default BuniChatWidget;\n"],"names":[],"mappings":";;;;AAQA;MACa,cAAc,CAAA;AAQzB,IAAA,WAAA,GAAA;QACE,IAAI,CAAC,KAAK,GAAG;AACX,YAAA,MAAM,EAAE,KAAK;AACb,YAAA,QAAQ,EAAE,KAAK;AACf,YAAA,WAAW,EAAE,KAAK;AAClB,YAAA,WAAW,EAAE,CAAC;SACf,CAAC;AACF,QAAA,IAAI,CAAC,cAAc,G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C;AAC1C,YAAA,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;AACd,gBAAA,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;aAC5B;SACF;aAAM;YACL,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;SACpC;KACF;IAED,IAAI,CAAC,KAAa,EAAE,IAAU,EAAA;QAC5B,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjD,IAAI,SAAS,EAAE;AACb,YAAA,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,KAAI;AAC7B,gBAAA,IAAI;oBACF,QAAQ,CAAC,IAAI,CAAC,CAAC;iBAChB;gBAAC,OAAO,KAAK,EAAE;oBACd,OAAO,CAAC,KAAK,CAAC,CAAA,4BAAA,EAA+B,KAAK,CAAG,CAAA,CAAA,EAAE,KAAK,CAAC,CAAC;iBAC/D;AACH,aAAC,CAAC,CAAC;SACJ;KACF;IAED,QAAQ,GAAA;AACN,QAAA,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;KAC1B;IAED,OAAO,GAAA;AACL,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;KAC5B;AACF,CAAA;AAED;AACM,SAAU,oBAAoB,CAAC,OAAwB,EAAA;AAC3D,IAAA,MAAM,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;AACpC,IAAA,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC3B,IAAA,OAAO,MAAM,CAAC;AAChB;;AC5WA;AAEA;;;;;;"}
package/dist/types.d.ts CHANGED
@@ -10,9 +10,14 @@ export interface BuniChatConfig {
10
10
  height?: number;
11
11
  triggerText?: string;
12
12
  autoOpen?: boolean;
13
+ minimized?: boolean;
14
+ allowMinimize?: boolean;
13
15
  showMinimize?: boolean;
14
16
  showBranding?: boolean;
15
17
  enableMobile?: boolean;
18
+ enableFileUpload?: boolean;
19
+ borderRadius?: string;
20
+ hideDefaultTrigger?: boolean;
16
21
  }
17
22
  export interface BuniChatOptions {
18
23
  token: string;
package/dist/widget.d.ts CHANGED
@@ -9,6 +9,9 @@ export declare class BuniChatWidget implements BuniChatAPI {
9
9
  constructor();
10
10
  initialize(options: BuniChatOptions): Promise<void>;
11
11
  private loadWidget;
12
+ private getPositionStyles;
13
+ private setupPostMessageAPI;
14
+ private postMessageToWidget;
12
15
  private initializeWidgetAPI;
13
16
  private getBaseUrl;
14
17
  destroy(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buni.ai/chatbot-core",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Core functionality for BuniAI chat widget adapters",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",