@robylon/web-react-sdk 1.1.28-staging.8 → 1.1.28
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/README.md +402 -34
- package/dist/cjs/index.js +1 -1215
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/ChatbotContainer/ChatbotContainer.d.ts +12 -0
- package/dist/cjs/types/components/ChatbotContainer/index.d.ts +1 -0
- package/dist/cjs/types/config.d.ts +1 -1
- package/dist/cjs/types/constants/fontStyles.d.ts +2 -0
- package/dist/cjs/types/core/api.d.ts +6 -54
- package/dist/cjs/types/core/config.d.ts +34 -0
- package/dist/cjs/types/core/events.d.ts +22 -0
- package/dist/cjs/types/core/index.d.ts +4 -0
- package/dist/cjs/types/core/state.d.ts +34 -0
- package/dist/cjs/types/index.d.ts +5 -9
- package/dist/cjs/types/types.d.ts +34 -9
- package/dist/cjs/types/utils/fetchData.d.ts +16 -0
- package/dist/cjs/types/vanilla/components/ChatbotContainer.d.ts +45 -0
- package/dist/cjs/types/vanilla/components/ChatbotFloatingButton.d.ts +69 -0
- package/dist/cjs/types/vanilla/components/ChatbotIframe.d.ts +71 -0
- package/dist/cjs/types/vanilla/index.d.ts +15 -29
- package/dist/esm/index.js +1 -1208
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/ChatbotContainer/ChatbotContainer.d.ts +12 -0
- package/dist/esm/types/components/ChatbotContainer/index.d.ts +1 -0
- package/dist/esm/types/config.d.ts +1 -1
- package/dist/esm/types/constants/fontStyles.d.ts +2 -0
- package/dist/esm/types/core/api.d.ts +6 -54
- package/dist/esm/types/core/config.d.ts +34 -0
- package/dist/esm/types/core/events.d.ts +22 -0
- package/dist/esm/types/core/index.d.ts +4 -0
- package/dist/esm/types/core/state.d.ts +34 -0
- package/dist/esm/types/index.d.ts +5 -9
- package/dist/esm/types/types.d.ts +34 -9
- package/dist/esm/types/utils/fetchData.d.ts +16 -0
- package/dist/esm/types/vanilla/components/ChatbotContainer.d.ts +45 -0
- package/dist/esm/types/vanilla/components/ChatbotFloatingButton.d.ts +69 -0
- package/dist/esm/types/vanilla/components/ChatbotIframe.d.ts +71 -0
- package/dist/esm/types/vanilla/index.d.ts +15 -29
- package/dist/index.d.ts +109 -57
- package/dist/umd/robylon-chatbot.js +2 -0
- package/dist/umd/robylon-chatbot.js.map +1 -0
- package/dist/umd/types/components/ChatbotContainer/ChatbotContainer.d.ts +12 -0
- package/dist/umd/types/components/ChatbotContainer/index.d.ts +1 -0
- package/dist/umd/types/config.d.ts +1 -1
- package/dist/umd/types/constants/fontStyles.d.ts +2 -0
- package/dist/umd/types/core/api.d.ts +6 -54
- package/dist/umd/types/core/config.d.ts +34 -0
- package/dist/umd/types/core/events.d.ts +22 -0
- package/dist/umd/types/core/index.d.ts +4 -0
- package/dist/umd/types/core/state.d.ts +34 -0
- package/dist/umd/types/index.d.ts +5 -9
- package/dist/umd/types/types.d.ts +34 -9
- package/dist/umd/types/utils/fetchData.d.ts +16 -0
- package/dist/umd/types/vanilla/components/ChatbotContainer.d.ts +45 -0
- package/dist/umd/types/vanilla/components/ChatbotFloatingButton.d.ts +69 -0
- package/dist/umd/types/vanilla/components/ChatbotIframe.d.ts +71 -0
- package/dist/umd/types/vanilla/index.d.ts +15 -29
- package/package.json +30 -85
- package/dist/cjs/legacy.js +0 -2
- package/dist/cjs/legacy.js.map +0 -1
- package/dist/cjs/react.js +0 -2
- package/dist/cjs/react.js.map +0 -1
- package/dist/cjs/types/core/chatbotEmbed.d.ts +0 -59
- package/dist/cjs/types/core/utils/color.d.ts +0 -1
- package/dist/cjs/types/core/utils/cookies.d.ts +0 -30
- package/dist/cjs/types/core/utils/environment.d.ts +0 -19
- package/dist/cjs/types/core/utils/logger.d.ts +0 -37
- package/dist/cjs/types/core/utils/system.d.ts +0 -22
- package/dist/cjs/types/index.legacy.d.ts +0 -7
- package/dist/cjs/types/index.react.d.ts +0 -9
- package/dist/cjs/types/index.vanilla.d.ts +0 -32
- package/dist/cjs/types/react/components/Chatbot.d.ts +0 -34
- package/dist/cjs/types/react/components/ErrorBoundary.d.ts +0 -18
- package/dist/cjs/types/types/config.d.ts +0 -33
- package/dist/cjs/types/types/index.d.ts +0 -16
- package/dist/esm/legacy.js +0 -2
- package/dist/esm/legacy.js.map +0 -1
- package/dist/esm/react.js +0 -2
- package/dist/esm/react.js.map +0 -1
- package/dist/esm/types/core/chatbotEmbed.d.ts +0 -59
- package/dist/esm/types/core/utils/color.d.ts +0 -1
- package/dist/esm/types/core/utils/cookies.d.ts +0 -30
- package/dist/esm/types/core/utils/environment.d.ts +0 -19
- package/dist/esm/types/core/utils/logger.d.ts +0 -37
- package/dist/esm/types/core/utils/system.d.ts +0 -22
- package/dist/esm/types/index.legacy.d.ts +0 -7
- package/dist/esm/types/index.react.d.ts +0 -9
- package/dist/esm/types/index.vanilla.d.ts +0 -32
- package/dist/esm/types/react/components/Chatbot.d.ts +0 -34
- package/dist/esm/types/react/components/ErrorBoundary.d.ts +0 -18
- package/dist/esm/types/types/config.d.ts +0 -33
- package/dist/esm/types/types/index.d.ts +0 -16
- package/dist/legacy.d.ts +0 -160
- package/dist/react.d.ts +0 -49
- package/dist/umd/robylon.js +0 -1230
- package/dist/umd/robylon.js.map +0 -1
- package/dist/umd/robylon.min.js +0 -2
- package/dist/umd/robylon.min.js.map +0 -1
- package/dist/umd/types/core/chatbotEmbed.d.ts +0 -59
- package/dist/umd/types/core/utils/color.d.ts +0 -1
- package/dist/umd/types/core/utils/cookies.d.ts +0 -30
- package/dist/umd/types/core/utils/environment.d.ts +0 -19
- package/dist/umd/types/core/utils/logger.d.ts +0 -37
- package/dist/umd/types/core/utils/system.d.ts +0 -22
- package/dist/umd/types/index.legacy.d.ts +0 -7
- package/dist/umd/types/index.react.d.ts +0 -9
- package/dist/umd/types/index.vanilla.d.ts +0 -32
- package/dist/umd/types/react/components/Chatbot.d.ts +0 -34
- package/dist/umd/types/react/components/ErrorBoundary.d.ts +0 -18
- package/dist/umd/types/types/config.d.ts +0 -33
- package/dist/umd/types/types/index.d.ts +0 -16
- package/dist/vite-compat.js +0 -76
package/dist/umd/robylon.js
DELETED
|
@@ -1,1230 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Robylon = {}));
|
|
5
|
-
})(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
// Ensure React is available
|
|
8
|
-
var React = (typeof window !== 'undefined' && window.React) || require('react');
|
|
9
|
-
var Chatbot; // Ensure Chatbot is available as a named export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/******************************************************************************
|
|
13
|
-
Copyright (c) Microsoft Corporation.
|
|
14
|
-
|
|
15
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
16
|
-
purpose with or without fee is hereby granted.
|
|
17
|
-
|
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
19
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
20
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
21
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
22
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
23
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
24
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
25
|
-
***************************************************************************** */
|
|
26
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
27
|
-
|
|
28
|
-
var extendStatics = function(d, b) {
|
|
29
|
-
extendStatics = Object.setPrototypeOf ||
|
|
30
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
31
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
32
|
-
return extendStatics(d, b);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
function __extends(d, b) {
|
|
36
|
-
if (typeof b !== "function" && b !== null)
|
|
37
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
38
|
-
extendStatics(d, b);
|
|
39
|
-
function __() { this.constructor = d; }
|
|
40
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
var __assign = function() {
|
|
44
|
-
__assign = Object.assign || function __assign(t) {
|
|
45
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
46
|
-
s = arguments[i];
|
|
47
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
48
|
-
}
|
|
49
|
-
return t;
|
|
50
|
-
};
|
|
51
|
-
return __assign.apply(this, arguments);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
55
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
56
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
57
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
58
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
59
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
60
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function __generator(thisArg, body) {
|
|
65
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
66
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
67
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
68
|
-
function step(op) {
|
|
69
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
70
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
71
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
72
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
73
|
-
switch (op[0]) {
|
|
74
|
-
case 0: case 1: t = op; break;
|
|
75
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
76
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
77
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
78
|
-
default:
|
|
79
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
80
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
81
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
82
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
83
|
-
if (t[2]) _.ops.pop();
|
|
84
|
-
_.trys.pop(); continue;
|
|
85
|
-
}
|
|
86
|
-
op = body.call(thisArg, _);
|
|
87
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
88
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function __spreadArray(to, from, pack) {
|
|
93
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
94
|
-
if (ar || !(i in from)) {
|
|
95
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
96
|
-
ar[i] = from[i];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
103
|
-
var e = new Error(message);
|
|
104
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
var getBestFontColor = function (backgroundColor, contrastThreshold) {
|
|
108
|
-
if (contrastThreshold === void 0) { contrastThreshold = 0.5; }
|
|
109
|
-
var whiteShade = "#FFFFFF"; // Light white shade
|
|
110
|
-
var blackShade = "#0E0E0F"; // Dark black shade
|
|
111
|
-
// Function to convert hex to RGB
|
|
112
|
-
var hexToRgb = function (hex) {
|
|
113
|
-
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
114
|
-
hex = hex.replace(shorthandRegex, function (m, r, g, b) { return r + r + g + g + b + b; });
|
|
115
|
-
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
116
|
-
return result
|
|
117
|
-
? {
|
|
118
|
-
r: parseInt(result[1], 16),
|
|
119
|
-
g: parseInt(result[2], 16),
|
|
120
|
-
b: parseInt(result[3], 16),
|
|
121
|
-
}
|
|
122
|
-
: { r: 0, g: 0, b: 0 };
|
|
123
|
-
};
|
|
124
|
-
// Function to calculate luminance
|
|
125
|
-
var luminance = function (r, g, b) {
|
|
126
|
-
var a = [r, g, b].map(function (v) {
|
|
127
|
-
v /= 255;
|
|
128
|
-
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
|
|
129
|
-
});
|
|
130
|
-
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
|
|
131
|
-
};
|
|
132
|
-
var _a = hexToRgb(backgroundColor), r = _a.r, g = _a.g, b = _a.b;
|
|
133
|
-
var bgLuminance = luminance(r, g, b);
|
|
134
|
-
return bgLuminance > contrastThreshold ? blackShade : whiteShade;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Cookie and storage utility functions
|
|
139
|
-
*/
|
|
140
|
-
/**
|
|
141
|
-
* Generates a UUID v4 string
|
|
142
|
-
*/
|
|
143
|
-
var generateUUID = function () {
|
|
144
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
145
|
-
var r = (Math.random() * 16) | 0, v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
146
|
-
return v.toString(16);
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
|
-
/**
|
|
150
|
-
* Gets a cookie by name
|
|
151
|
-
*/
|
|
152
|
-
var getCookie = function (name) {
|
|
153
|
-
var _a;
|
|
154
|
-
if (typeof document === "undefined")
|
|
155
|
-
return undefined;
|
|
156
|
-
var value = "; ".concat(document.cookie);
|
|
157
|
-
var parts = value.split("; ".concat(name, "="));
|
|
158
|
-
if (parts.length === 2)
|
|
159
|
-
return (_a = parts.pop()) === null || _a === void 0 ? void 0 : _a.split(";").shift();
|
|
160
|
-
return undefined;
|
|
161
|
-
};
|
|
162
|
-
/**
|
|
163
|
-
* Sets a cookie with expiration in days
|
|
164
|
-
*/
|
|
165
|
-
var setCookie = function (name, value, days) {
|
|
166
|
-
if (typeof document === "undefined")
|
|
167
|
-
return;
|
|
168
|
-
var expires = new Date();
|
|
169
|
-
expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
|
|
170
|
-
document.cookie = "".concat(name, "=").concat(value, ";expires=").concat(expires.toUTCString(), ";path=/");
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* Gets all localStorage as a JSON string
|
|
174
|
-
*/
|
|
175
|
-
var getLocalStorage = function () {
|
|
176
|
-
if (typeof localStorage === "undefined")
|
|
177
|
-
return "{}";
|
|
178
|
-
try {
|
|
179
|
-
return JSON.stringify(localStorage);
|
|
180
|
-
}
|
|
181
|
-
catch (e) {
|
|
182
|
-
console.error("Error stringifying localStorage:", e);
|
|
183
|
-
return "{}";
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* Gets all sessionStorage as a JSON string
|
|
188
|
-
*/
|
|
189
|
-
var getSessionStorage = function () {
|
|
190
|
-
if (typeof sessionStorage === "undefined")
|
|
191
|
-
return "{}";
|
|
192
|
-
try {
|
|
193
|
-
return JSON.stringify(sessionStorage);
|
|
194
|
-
}
|
|
195
|
-
catch (e) {
|
|
196
|
-
console.error("Error stringifying sessionStorage:", e);
|
|
197
|
-
return "{}";
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
/**
|
|
201
|
-
* Gets all cookies as an array of objects
|
|
202
|
-
*/
|
|
203
|
-
var getCookies = function (isTeachmint) {
|
|
204
|
-
if (typeof document === "undefined")
|
|
205
|
-
return [];
|
|
206
|
-
try {
|
|
207
|
-
// Note: The teachmint specific code has been simplified for the core library
|
|
208
|
-
// If specific implementations are needed, they should be handled in the application layer
|
|
209
|
-
var cookieStr = document.cookie;
|
|
210
|
-
if (cookieStr === "")
|
|
211
|
-
return [];
|
|
212
|
-
var cookies = cookieStr.split(";").map(function (cookie) {
|
|
213
|
-
var _a = cookie.split("="), name = _a[0], rest = _a.slice(1);
|
|
214
|
-
var value = rest.join("=").trim();
|
|
215
|
-
name = name.trim();
|
|
216
|
-
return {
|
|
217
|
-
name: name,
|
|
218
|
-
value: value ? decodeURIComponent(value) : "",
|
|
219
|
-
};
|
|
220
|
-
});
|
|
221
|
-
return cookies;
|
|
222
|
-
}
|
|
223
|
-
catch (e) {
|
|
224
|
-
console.error("Error processing cookies:", e);
|
|
225
|
-
return [];
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Core ChatbotEmbed class - provides the main functionality for both React and vanilla JS implementations
|
|
231
|
-
*/
|
|
232
|
-
var ChatbotEmbed = /** @class */ (function () {
|
|
233
|
-
function ChatbotEmbed(config) {
|
|
234
|
-
var _this = this;
|
|
235
|
-
this.logoContainer = null;
|
|
236
|
-
this.iframe = null;
|
|
237
|
-
this.bubblePromptContainer = null;
|
|
238
|
-
this.chatBtnImage = null;
|
|
239
|
-
this.eventHandlers = new Map();
|
|
240
|
-
this.isInitialized = false;
|
|
241
|
-
this.onMessageListener = function (event) {
|
|
242
|
-
if (event.origin === _this.config.domain) {
|
|
243
|
-
if (event.data === "closeChatbot") {
|
|
244
|
-
_this.closeIframe();
|
|
245
|
-
_this.emit("CHATBOT_CLOSED");
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
// Handle structured events
|
|
249
|
-
if (typeof event.data === "object" && event.data !== null) {
|
|
250
|
-
// Handle specific event types
|
|
251
|
-
if (event.data.type === "CHATBOT_LOADED") {
|
|
252
|
-
_this.emit("CHATBOT_LOADED", event.data);
|
|
253
|
-
}
|
|
254
|
-
else if (event.data.type === "CHAT_INITIALIZED") {
|
|
255
|
-
_this.emit("CHAT_INITIALIZED", event.data);
|
|
256
|
-
}
|
|
257
|
-
else if (event.data.type === "CHAT_INITIALIZATION_FAILED") {
|
|
258
|
-
_this.emit("CHAT_INITIALIZATION_FAILED", event.data);
|
|
259
|
-
}
|
|
260
|
-
else if (event.data.type === "SESSION_REFRESHED") {
|
|
261
|
-
_this.emit("SESSION_REFRESHED", event.data);
|
|
262
|
-
}
|
|
263
|
-
else if (event.data.type === "CHATBOT_TOKEN_EXHAUSTED") {
|
|
264
|
-
_this.emit("CHATBOT_TOKEN_EXHAUSTED", event.data);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
// Special commands
|
|
268
|
-
if (event.data === "captureSessionData") {
|
|
269
|
-
_this.handleCaptureSessionData();
|
|
270
|
-
}
|
|
271
|
-
if (event.data === "expand") {
|
|
272
|
-
_this.adjustIframeWidth();
|
|
273
|
-
if (_this.iframe) {
|
|
274
|
-
_this.iframe.style.height = "calc(100vh - 120px)";
|
|
275
|
-
_this.iframe.style.bottom = "86px";
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
if (event.data === "collapse") {
|
|
279
|
-
if (_this.iframe) {
|
|
280
|
-
_this.iframe.style.width = "26%";
|
|
281
|
-
_this.iframe.style.height = "calc(100vh - 32px - 10vh)";
|
|
282
|
-
_this.iframe.style.bottom = "86px";
|
|
283
|
-
_this.iframe.style.top = "auto";
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
this.config = config;
|
|
289
|
-
// Normalize the config
|
|
290
|
-
if (typeof this.config.userId === "number") {
|
|
291
|
-
this.config.userId = String(this.config.userId);
|
|
292
|
-
}
|
|
293
|
-
if (this.validateConfig()) {
|
|
294
|
-
this.init();
|
|
295
|
-
this.setupEventListeners();
|
|
296
|
-
this.isInitialized = true;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
// Public API methods
|
|
300
|
-
ChatbotEmbed.prototype.show = function () {
|
|
301
|
-
if (!this.isInitialized || !this.iframe)
|
|
302
|
-
return;
|
|
303
|
-
this.showIframe();
|
|
304
|
-
this.emit("CHATBOT_OPENED");
|
|
305
|
-
};
|
|
306
|
-
ChatbotEmbed.prototype.hide = function () {
|
|
307
|
-
if (!this.isInitialized || !this.iframe)
|
|
308
|
-
return;
|
|
309
|
-
this.closeIframe();
|
|
310
|
-
this.emit("CHATBOT_CLOSED");
|
|
311
|
-
};
|
|
312
|
-
ChatbotEmbed.prototype.toggle = function () {
|
|
313
|
-
if (!this.isInitialized)
|
|
314
|
-
return;
|
|
315
|
-
if (this.iframe && this.iframe.style.display === "none") {
|
|
316
|
-
this.show();
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
this.hide();
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
ChatbotEmbed.prototype.updateConfig = function (newConfig) {
|
|
323
|
-
var _a;
|
|
324
|
-
this.config = __assign(__assign({}, this.config), newConfig);
|
|
325
|
-
// Update UI if needed
|
|
326
|
-
if (newConfig.brand_colour && this.logoContainer) {
|
|
327
|
-
this.logoContainer.style.backgroundColor = newConfig.brand_colour;
|
|
328
|
-
this.logoContainer.style.color = getBestFontColor(newConfig.brand_colour);
|
|
329
|
-
}
|
|
330
|
-
if (newConfig.image_url && this.logoContainer) {
|
|
331
|
-
this.loadImage(this.logoContainer);
|
|
332
|
-
}
|
|
333
|
-
// Update user profile in iframe if it's visible
|
|
334
|
-
if (newConfig.userProfile &&
|
|
335
|
-
this.iframe &&
|
|
336
|
-
this.iframe.style.display === "block") {
|
|
337
|
-
(_a = this.iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
338
|
-
action: "updateUserProfile",
|
|
339
|
-
user_profile: newConfig.userProfile,
|
|
340
|
-
}, this.config.domain);
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
// Event system
|
|
344
|
-
ChatbotEmbed.prototype.on = function (eventName, callback) {
|
|
345
|
-
var _a;
|
|
346
|
-
if (!this.eventHandlers.has(eventName)) {
|
|
347
|
-
this.eventHandlers.set(eventName, []);
|
|
348
|
-
}
|
|
349
|
-
(_a = this.eventHandlers.get(eventName)) === null || _a === void 0 ? void 0 : _a.push(callback);
|
|
350
|
-
};
|
|
351
|
-
ChatbotEmbed.prototype.off = function (eventName, callback) {
|
|
352
|
-
if (!this.eventHandlers.has(eventName))
|
|
353
|
-
return;
|
|
354
|
-
var handlers = this.eventHandlers.get(eventName) || [];
|
|
355
|
-
var index = handlers.indexOf(callback);
|
|
356
|
-
if (index !== -1) {
|
|
357
|
-
handlers.splice(index, 1);
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
ChatbotEmbed.prototype.emit = function (eventType, data) {
|
|
361
|
-
var event = {
|
|
362
|
-
type: eventType,
|
|
363
|
-
timestamp: Date.now(),
|
|
364
|
-
data: data,
|
|
365
|
-
};
|
|
366
|
-
// Call specific event handlers
|
|
367
|
-
var handlers = this.eventHandlers.get(eventType) || [];
|
|
368
|
-
handlers.forEach(function (handler) { return handler(event); });
|
|
369
|
-
// Call wildcard handlers
|
|
370
|
-
var wildcardHandlers = this.eventHandlers.get("*") || [];
|
|
371
|
-
wildcardHandlers.forEach(function (handler) { return handler(event); });
|
|
372
|
-
};
|
|
373
|
-
// Cleanup
|
|
374
|
-
ChatbotEmbed.prototype.destroy = function () {
|
|
375
|
-
// Remove DOM elements
|
|
376
|
-
if (this.iframe) {
|
|
377
|
-
document.body.removeChild(this.iframe);
|
|
378
|
-
this.iframe = null;
|
|
379
|
-
}
|
|
380
|
-
if (this.logoContainer) {
|
|
381
|
-
document.body.removeChild(this.logoContainer);
|
|
382
|
-
this.logoContainer = null;
|
|
383
|
-
}
|
|
384
|
-
if (this.bubblePromptContainer) {
|
|
385
|
-
document.body.removeChild(this.bubblePromptContainer);
|
|
386
|
-
this.bubblePromptContainer = null;
|
|
387
|
-
}
|
|
388
|
-
// Remove event listeners
|
|
389
|
-
window === null || window === void 0 ? void 0 : window.removeEventListener("message", this.onMessageListener);
|
|
390
|
-
// Clear event handlers
|
|
391
|
-
this.eventHandlers.clear();
|
|
392
|
-
this.isInitialized = false;
|
|
393
|
-
};
|
|
394
|
-
// Private methods
|
|
395
|
-
ChatbotEmbed.prototype.validateConfig = function () {
|
|
396
|
-
if (!this.config.chatbotId) {
|
|
397
|
-
console.error("ChatbotEmbed: Missing required chatbotId");
|
|
398
|
-
return false;
|
|
399
|
-
}
|
|
400
|
-
return true;
|
|
401
|
-
};
|
|
402
|
-
ChatbotEmbed.prototype.setupEventListeners = function () {
|
|
403
|
-
window === null || window === void 0 ? void 0 : window.addEventListener("message", this.onMessageListener);
|
|
404
|
-
};
|
|
405
|
-
ChatbotEmbed.prototype.init = function () {
|
|
406
|
-
this.createIframe();
|
|
407
|
-
this.createFloatingButton();
|
|
408
|
-
};
|
|
409
|
-
ChatbotEmbed.prototype.createFloatingButton = function () {
|
|
410
|
-
var _this = this;
|
|
411
|
-
var div = document.createElement("div");
|
|
412
|
-
div.classList.add("message-bubble-container");
|
|
413
|
-
Object.assign(div.style, {
|
|
414
|
-
position: "fixed",
|
|
415
|
-
bottom: "1.5rem",
|
|
416
|
-
right: "1.5rem",
|
|
417
|
-
zIndex: "1000",
|
|
418
|
-
width: "48px",
|
|
419
|
-
height: "48px",
|
|
420
|
-
display: "flex",
|
|
421
|
-
flexDirection: "column-reverse",
|
|
422
|
-
backgroundColor: this.config.brand_colour,
|
|
423
|
-
color: getBestFontColor(this.config.brand_colour),
|
|
424
|
-
borderRadius: "50%",
|
|
425
|
-
alignItems: "center",
|
|
426
|
-
justifyContent: "center",
|
|
427
|
-
cursor: "pointer",
|
|
428
|
-
overflow: "hidden",
|
|
429
|
-
});
|
|
430
|
-
document.body.appendChild(div);
|
|
431
|
-
this.logoContainer = div;
|
|
432
|
-
this.loadImage(this.logoContainer);
|
|
433
|
-
this.createChatBubblContainer();
|
|
434
|
-
this.logoContainer.addEventListener("click", this.toggleIframe.bind(this));
|
|
435
|
-
// Emit button loaded event
|
|
436
|
-
setTimeout(function () {
|
|
437
|
-
_this.emit("CHATBOT_BUTTON_LOADED");
|
|
438
|
-
}, 0);
|
|
439
|
-
};
|
|
440
|
-
ChatbotEmbed.prototype.createChatBubblContainer = function () {
|
|
441
|
-
var _this = this;
|
|
442
|
-
var _a;
|
|
443
|
-
var chatbaseContainer = document.createElement("div");
|
|
444
|
-
chatbaseContainer.id = "chatbase-message-bubbles";
|
|
445
|
-
Object.assign(chatbaseContainer.style, {
|
|
446
|
-
position: "fixed",
|
|
447
|
-
bottom: "80px",
|
|
448
|
-
borderRadius: "10px",
|
|
449
|
-
fontFamily: "sans-serif",
|
|
450
|
-
fontSize: "16px",
|
|
451
|
-
zIndex: "2147483644",
|
|
452
|
-
cursor: "pointer",
|
|
453
|
-
flexDirection: "column",
|
|
454
|
-
gap: "50px",
|
|
455
|
-
maxWidth: "70vw",
|
|
456
|
-
display: "block",
|
|
457
|
-
right: "1rem",
|
|
458
|
-
left: "unset",
|
|
459
|
-
});
|
|
460
|
-
var closeButton = document.createElement("div");
|
|
461
|
-
closeButton.classList.add("close-btn");
|
|
462
|
-
closeButton.textContent = "✕";
|
|
463
|
-
Object.assign(closeButton.style, {
|
|
464
|
-
position: "absolute",
|
|
465
|
-
top: "-7px",
|
|
466
|
-
right: "-7px",
|
|
467
|
-
fontWeight: "bold",
|
|
468
|
-
display: "none",
|
|
469
|
-
justifyContent: "center",
|
|
470
|
-
alignItems: "center",
|
|
471
|
-
zIndex: "2147483643",
|
|
472
|
-
width: "22px",
|
|
473
|
-
height: "22px",
|
|
474
|
-
borderRadius: "50%",
|
|
475
|
-
textAlign: "center",
|
|
476
|
-
fontSize: "12px",
|
|
477
|
-
cursor: "pointer",
|
|
478
|
-
backgroundColor: "rgb(224, 224, 224)",
|
|
479
|
-
color: "black",
|
|
480
|
-
boxShadow: "rgba(150, 150, 150, 0.15) 0px 6px 24px 0px, rgba(150, 150, 150, 0.15) 0px 0px 0px 1px",
|
|
481
|
-
});
|
|
482
|
-
var prompts = ((_a = this.config.chat_interface_config) === null || _a === void 0 ? void 0 : _a.chat_bubble_prompts) || [];
|
|
483
|
-
prompts.forEach(function (prompt) {
|
|
484
|
-
var messageBubble = _this.createMessageBubble(prompt);
|
|
485
|
-
chatbaseContainer.appendChild(messageBubble);
|
|
486
|
-
});
|
|
487
|
-
chatbaseContainer.appendChild(closeButton);
|
|
488
|
-
document.body.appendChild(chatbaseContainer);
|
|
489
|
-
};
|
|
490
|
-
ChatbotEmbed.prototype.createMessageBubble = function (message) {
|
|
491
|
-
var bubble = document.createElement("div");
|
|
492
|
-
this.bubblePromptContainer = bubble;
|
|
493
|
-
Object.assign(bubble.style, {
|
|
494
|
-
display: "flex",
|
|
495
|
-
position: "relative",
|
|
496
|
-
justifyContent: "flex-end",
|
|
497
|
-
});
|
|
498
|
-
var messageContent = document.createElement("div");
|
|
499
|
-
messageContent.classList.add("message");
|
|
500
|
-
messageContent.textContent = message;
|
|
501
|
-
Object.assign(messageContent.style, {
|
|
502
|
-
backgroundColor: "white",
|
|
503
|
-
color: "black",
|
|
504
|
-
boxShadow: "rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px",
|
|
505
|
-
borderRadius: "10px",
|
|
506
|
-
padding: "8px 5px",
|
|
507
|
-
margin: "8px",
|
|
508
|
-
fontSize: "14px",
|
|
509
|
-
opacity: "1",
|
|
510
|
-
transform: "scale(1)",
|
|
511
|
-
transition: "opacity 0.5s ease 0s, transform 0.5s ease 0s",
|
|
512
|
-
});
|
|
513
|
-
var closeButton = document.createElement("button");
|
|
514
|
-
closeButton.innerHTML = "×";
|
|
515
|
-
Object.assign(closeButton.style, {
|
|
516
|
-
position: "absolute",
|
|
517
|
-
top: "1px",
|
|
518
|
-
left: "-3px",
|
|
519
|
-
width: "20px",
|
|
520
|
-
height: "20px",
|
|
521
|
-
borderRadius: "50%",
|
|
522
|
-
backgroundColor: "#fff",
|
|
523
|
-
color: "#000",
|
|
524
|
-
border: "none",
|
|
525
|
-
cursor: "pointer",
|
|
526
|
-
display: "flex",
|
|
527
|
-
alignItems: "center",
|
|
528
|
-
justifyContent: "center",
|
|
529
|
-
boxShadow: "0 2px 5px rgba(0,0,0,0.2)",
|
|
530
|
-
fontSize: "14px",
|
|
531
|
-
lineHeight: "1",
|
|
532
|
-
padding: "0",
|
|
533
|
-
zIndex: "100",
|
|
534
|
-
});
|
|
535
|
-
closeButton.addEventListener("click", function () {
|
|
536
|
-
bubble.remove();
|
|
537
|
-
});
|
|
538
|
-
bubble.appendChild(closeButton);
|
|
539
|
-
bubble.appendChild(messageContent);
|
|
540
|
-
return bubble;
|
|
541
|
-
};
|
|
542
|
-
ChatbotEmbed.prototype.createIframe = function () {
|
|
543
|
-
var _this = this;
|
|
544
|
-
var iframe = document.createElement("iframe");
|
|
545
|
-
Object.assign(iframe.style, {
|
|
546
|
-
position: "fixed",
|
|
547
|
-
right: "32px",
|
|
548
|
-
bottom: "86px",
|
|
549
|
-
minWidth: "400px",
|
|
550
|
-
width: "26%",
|
|
551
|
-
maxWidth: "560px",
|
|
552
|
-
top: "auto",
|
|
553
|
-
maxHeight: "45rem",
|
|
554
|
-
height: "calc(100vh - 3rem - 10vh)",
|
|
555
|
-
zIndex: "20000000",
|
|
556
|
-
border: "none",
|
|
557
|
-
boxShadow: "0px 0px 40px 0px rgba(14, 14, 15, 0.24)",
|
|
558
|
-
transformOrigin: "bottom right",
|
|
559
|
-
transition: "transform 0.3s ease-out",
|
|
560
|
-
borderRadius: "1rem",
|
|
561
|
-
display: "none",
|
|
562
|
-
});
|
|
563
|
-
iframe.src = "".concat(this.config.domain, "/chatbot-plugin?id=").concat(this.config.chatbotId);
|
|
564
|
-
document.body.appendChild(iframe);
|
|
565
|
-
this.iframe = iframe;
|
|
566
|
-
// Media Query Handling
|
|
567
|
-
var applyStylesBasedOnScreenWidth = function () {
|
|
568
|
-
if ((window === null || window === void 0 ? void 0 : window.innerWidth) < 560) {
|
|
569
|
-
// Styles for screen width below 560px
|
|
570
|
-
Object.assign(iframe.style, {
|
|
571
|
-
width: "100vw",
|
|
572
|
-
minWidth: "300px",
|
|
573
|
-
right: "0",
|
|
574
|
-
bottom: "0",
|
|
575
|
-
height: "100vh",
|
|
576
|
-
flexDirection: "column",
|
|
577
|
-
flexGrow: "1",
|
|
578
|
-
borderRadius: "0",
|
|
579
|
-
top: "0",
|
|
580
|
-
maxHeight: "100%",
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
else {
|
|
584
|
-
// Styles for screen width above 560px
|
|
585
|
-
Object.assign(iframe.style, {
|
|
586
|
-
width: "26%",
|
|
587
|
-
maxWidth: "560px",
|
|
588
|
-
minWidth: "400px",
|
|
589
|
-
right: "32px",
|
|
590
|
-
bottom: "86px",
|
|
591
|
-
height: "calc(100vh - 3rem - 10vh)",
|
|
592
|
-
borderRadius: "1rem",
|
|
593
|
-
top: "auto",
|
|
594
|
-
maxHeight: "45rem",
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
};
|
|
598
|
-
applyStylesBasedOnScreenWidth();
|
|
599
|
-
// Set up window resize handler
|
|
600
|
-
window === null || window === void 0 ? void 0 : window.addEventListener("resize", applyStylesBasedOnScreenWidth);
|
|
601
|
-
// Set up iframe load handler
|
|
602
|
-
iframe.addEventListener("load", function () {
|
|
603
|
-
var _a, _b, _c, _d;
|
|
604
|
-
if (!_this.iframe)
|
|
605
|
-
return;
|
|
606
|
-
var targetOrigin = new URL(_this.iframe.src).origin || _this.config.domain;
|
|
607
|
-
(_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage({ domain: (_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.hostname, name: "checkDomain" }, targetOrigin);
|
|
608
|
-
(_c = iframe.contentWindow) === null || _c === void 0 ? void 0 : _c.postMessage({
|
|
609
|
-
domain: (_d = window === null || window === void 0 ? void 0 : window.location) === null || _d === void 0 ? void 0 : _d.hostname,
|
|
610
|
-
action: "registerUserId",
|
|
611
|
-
data: {
|
|
612
|
-
userId: _this.config.userId,
|
|
613
|
-
token: _this.config.token,
|
|
614
|
-
userProfile: _this.config.userProfile,
|
|
615
|
-
isAnonymous: _this.config.isAnonymous,
|
|
616
|
-
},
|
|
617
|
-
}, targetOrigin);
|
|
618
|
-
});
|
|
619
|
-
};
|
|
620
|
-
ChatbotEmbed.prototype.loadImage = function (containerElement) {
|
|
621
|
-
var image = document.createElement("img");
|
|
622
|
-
image.src = this.config.image_url || "".concat(this.config.domain, "/chatbubble.png");
|
|
623
|
-
image.alt = "Chat";
|
|
624
|
-
Object.assign(image.style, {
|
|
625
|
-
zIndex: "1000",
|
|
626
|
-
cursor: "pointer",
|
|
627
|
-
borderRadius: "50%",
|
|
628
|
-
objectFit: "cover",
|
|
629
|
-
width: "100%",
|
|
630
|
-
height: "100%",
|
|
631
|
-
});
|
|
632
|
-
this.chatBtnImage = image;
|
|
633
|
-
containerElement.innerHTML = ""; // Clear any existing content
|
|
634
|
-
containerElement.appendChild(image);
|
|
635
|
-
};
|
|
636
|
-
ChatbotEmbed.prototype.loadSvgInline = function (containerElement) {
|
|
637
|
-
var svgChevronDown = "\n<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <g id=\"Chevron_Down\">\n <path id=\"Vector\" d=\"M19 9L12 16L5 9\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </g>\n</svg>\n";
|
|
638
|
-
// Create a temporary container to insert the SVG content
|
|
639
|
-
var tempDiv = document.createElement("div");
|
|
640
|
-
tempDiv.innerHTML = svgChevronDown;
|
|
641
|
-
// Find the <svg> element
|
|
642
|
-
var svgElement = tempDiv.querySelector("svg");
|
|
643
|
-
// Clear the existing content in the container and inject the SVG
|
|
644
|
-
containerElement.innerHTML = ""; // Clear any existing content
|
|
645
|
-
if (svgElement) {
|
|
646
|
-
containerElement.appendChild(svgElement);
|
|
647
|
-
}
|
|
648
|
-
};
|
|
649
|
-
ChatbotEmbed.prototype.toggleIcon = function (containerElement, iframe) {
|
|
650
|
-
if (iframe.style.display === "block") {
|
|
651
|
-
// Load the SVG Chevron Down when iframe is visible
|
|
652
|
-
this.loadSvgInline(containerElement);
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
// Load the image when iframe is hidden
|
|
656
|
-
this.loadImage(containerElement);
|
|
657
|
-
}
|
|
658
|
-
};
|
|
659
|
-
ChatbotEmbed.prototype.toggleIframe = function () {
|
|
660
|
-
if (!this.iframe || !this.logoContainer || !this.chatBtnImage)
|
|
661
|
-
return;
|
|
662
|
-
if (this.iframe.style.display === "none") {
|
|
663
|
-
this.showIframe();
|
|
664
|
-
this.emit("CHATBOT_BUTTON_CLICKED");
|
|
665
|
-
this.emit("CHATBOT_OPENED");
|
|
666
|
-
}
|
|
667
|
-
else {
|
|
668
|
-
this.closeIframe();
|
|
669
|
-
this.emit("CHATBOT_CLOSED");
|
|
670
|
-
}
|
|
671
|
-
};
|
|
672
|
-
ChatbotEmbed.prototype.showIframe = function () {
|
|
673
|
-
var _a;
|
|
674
|
-
if (!this.iframe || !this.logoContainer || !this.chatBtnImage)
|
|
675
|
-
return;
|
|
676
|
-
var targetOrigin = new URL(this.iframe.src).origin || this.config.domain;
|
|
677
|
-
this.iframe.style.display = "block";
|
|
678
|
-
(_a = this.iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
679
|
-
domain: window === null || window === void 0 ? void 0 : window.location.hostname,
|
|
680
|
-
name: "openFrame",
|
|
681
|
-
}, targetOrigin);
|
|
682
|
-
this.toggleIcon(this.logoContainer, this.iframe);
|
|
683
|
-
this.chatBtnImage.style.objectFit = "none";
|
|
684
|
-
if (this.bubblePromptContainer) {
|
|
685
|
-
this.bubblePromptContainer.style.display = "none";
|
|
686
|
-
}
|
|
687
|
-
};
|
|
688
|
-
ChatbotEmbed.prototype.closeIframe = function () {
|
|
689
|
-
if (!this.iframe || !this.logoContainer || !this.chatBtnImage)
|
|
690
|
-
return;
|
|
691
|
-
this.iframe.style.display = "none";
|
|
692
|
-
this.toggleIcon(this.logoContainer, this.iframe);
|
|
693
|
-
this.chatBtnImage.style.objectFit = "cover";
|
|
694
|
-
};
|
|
695
|
-
ChatbotEmbed.prototype.adjustIframeWidth = function () {
|
|
696
|
-
if (!this.iframe)
|
|
697
|
-
return;
|
|
698
|
-
var screenWidth = window === null || window === void 0 ? void 0 : window.innerWidth;
|
|
699
|
-
if (screenWidth < 832) {
|
|
700
|
-
this.iframe.style.width = "".concat(screenWidth - 64, "px");
|
|
701
|
-
}
|
|
702
|
-
else {
|
|
703
|
-
this.iframe.style.width = "800px";
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
ChatbotEmbed.prototype.handleCaptureSessionData = function () {
|
|
707
|
-
var _a, _b;
|
|
708
|
-
if (!this.iframe)
|
|
709
|
-
return;
|
|
710
|
-
var data = {
|
|
711
|
-
cookies: getCookies(), // TODO: Handle the isTeachmint parameter better
|
|
712
|
-
localStorage: getLocalStorage(),
|
|
713
|
-
sessionStorage: getSessionStorage(),
|
|
714
|
-
action: "capturedSessionData",
|
|
715
|
-
domain_name: (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.hostname,
|
|
716
|
-
user_profile: this.config.userProfile,
|
|
717
|
-
};
|
|
718
|
-
(_b = this.iframe.contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage(data, this.config.domain || "*");
|
|
719
|
-
};
|
|
720
|
-
return ChatbotEmbed;
|
|
721
|
-
}());
|
|
722
|
-
|
|
723
|
-
/**
|
|
724
|
-
* Environment configuration for the SDK
|
|
725
|
-
*/
|
|
726
|
-
// Get current environment from build-time
|
|
727
|
-
var NODE_ENV = "staging" ;
|
|
728
|
-
// Default configuration values based on environment
|
|
729
|
-
var DEFAULT_CONFIG = {
|
|
730
|
-
// Default URLs for each environment
|
|
731
|
-
copilotUrl: {
|
|
732
|
-
development: "https://dev.robylon.ai",
|
|
733
|
-
staging: "https://staging.d2s3wsqyyond1h.amplifyapp.com",
|
|
734
|
-
production: "https://app.robylon.ai",
|
|
735
|
-
},
|
|
736
|
-
environment: NODE_ENV,
|
|
737
|
-
apiUrl: {
|
|
738
|
-
development: "https://dev-api.robylon.ai",
|
|
739
|
-
staging: "https://stage-api.robylon.ai",
|
|
740
|
-
production: "https://api.robylon.ai",
|
|
741
|
-
},
|
|
742
|
-
};
|
|
743
|
-
// Store custom config values
|
|
744
|
-
var customConfig = {};
|
|
745
|
-
/**
|
|
746
|
-
* Set custom environment configuration
|
|
747
|
-
*/
|
|
748
|
-
var setEnvironmentConfig = function (config) {
|
|
749
|
-
customConfig = __assign(__assign({}, customConfig), config);
|
|
750
|
-
};
|
|
751
|
-
/**
|
|
752
|
-
* Gets environment configuration with defaults
|
|
753
|
-
*/
|
|
754
|
-
var getEnvironmentConfig = function () {
|
|
755
|
-
// Determine current environment
|
|
756
|
-
var environment = customConfig.environment || NODE_ENV;
|
|
757
|
-
// Ensure we pick URLs appropriate for the current environment
|
|
758
|
-
var envType = environment === "staging"
|
|
759
|
-
? "staging"
|
|
760
|
-
: environment === "development"
|
|
761
|
-
? "development"
|
|
762
|
-
: "production";
|
|
763
|
-
// Get default values for current environment
|
|
764
|
-
var defaultCopilotUrl = DEFAULT_CONFIG.copilotUrl[envType];
|
|
765
|
-
var defaultApiUrl = DEFAULT_CONFIG.apiUrl[envType];
|
|
766
|
-
return {
|
|
767
|
-
copilotUrl: customConfig.copilotUrl || defaultCopilotUrl,
|
|
768
|
-
environment: environment,
|
|
769
|
-
apiUrl: customConfig.apiUrl || defaultApiUrl,
|
|
770
|
-
};
|
|
771
|
-
};
|
|
772
|
-
|
|
773
|
-
/**
|
|
774
|
-
* Simple logger class with configurable log level
|
|
775
|
-
*/
|
|
776
|
-
var Logger = /** @class */ (function () {
|
|
777
|
-
function Logger() {
|
|
778
|
-
this.level = "info";
|
|
779
|
-
this.isEnabled = true;
|
|
780
|
-
}
|
|
781
|
-
/**
|
|
782
|
-
* Set the log level
|
|
783
|
-
*/
|
|
784
|
-
Logger.prototype.setLevel = function (level) {
|
|
785
|
-
this.level = level;
|
|
786
|
-
};
|
|
787
|
-
/**
|
|
788
|
-
* Enable or disable logging
|
|
789
|
-
*/
|
|
790
|
-
Logger.prototype.setEnabled = function (enabled) {
|
|
791
|
-
this.isEnabled = enabled;
|
|
792
|
-
};
|
|
793
|
-
/**
|
|
794
|
-
* Log debug level messages
|
|
795
|
-
*/
|
|
796
|
-
Logger.prototype.debug = function () {
|
|
797
|
-
var args = [];
|
|
798
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
799
|
-
args[_i] = arguments[_i];
|
|
800
|
-
}
|
|
801
|
-
if (!this.isEnabled || this.level === "none")
|
|
802
|
-
return;
|
|
803
|
-
if (["debug"].includes(this.level)) {
|
|
804
|
-
console.debug.apply(console, __spreadArray(["[Robylon Debug]"], args, false));
|
|
805
|
-
}
|
|
806
|
-
};
|
|
807
|
-
/**
|
|
808
|
-
* Log informational messages
|
|
809
|
-
*/
|
|
810
|
-
Logger.prototype.log = function () {
|
|
811
|
-
var args = [];
|
|
812
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
813
|
-
args[_i] = arguments[_i];
|
|
814
|
-
}
|
|
815
|
-
if (!this.isEnabled || this.level === "none")
|
|
816
|
-
return;
|
|
817
|
-
if (["debug", "info"].includes(this.level)) {
|
|
818
|
-
console.log.apply(console, __spreadArray(["[Robylon]"], args, false));
|
|
819
|
-
}
|
|
820
|
-
};
|
|
821
|
-
/**
|
|
822
|
-
* Log warning messages
|
|
823
|
-
*/
|
|
824
|
-
Logger.prototype.warn = function () {
|
|
825
|
-
var args = [];
|
|
826
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
827
|
-
args[_i] = arguments[_i];
|
|
828
|
-
}
|
|
829
|
-
if (!this.isEnabled || this.level === "none")
|
|
830
|
-
return;
|
|
831
|
-
if (["debug", "info", "warn"].includes(this.level)) {
|
|
832
|
-
console.warn.apply(console, __spreadArray(["[Robylon Warn]"], args, false));
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
/**
|
|
836
|
-
* Log error messages
|
|
837
|
-
*/
|
|
838
|
-
Logger.prototype.error = function () {
|
|
839
|
-
var args = [];
|
|
840
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
841
|
-
args[_i] = arguments[_i];
|
|
842
|
-
}
|
|
843
|
-
if (!this.isEnabled || this.level === "none")
|
|
844
|
-
return;
|
|
845
|
-
if (["debug", "info", "warn", "error"].includes(this.level)) {
|
|
846
|
-
console.error.apply(console, __spreadArray(["[Robylon Error]"], args, false));
|
|
847
|
-
}
|
|
848
|
-
};
|
|
849
|
-
return Logger;
|
|
850
|
-
}());
|
|
851
|
-
/**
|
|
852
|
-
* Singleton logger instance
|
|
853
|
-
*/
|
|
854
|
-
var logger = new Logger();
|
|
855
|
-
|
|
856
|
-
/**
|
|
857
|
-
* Error codes for API operations
|
|
858
|
-
*/
|
|
859
|
-
var ApiErrorCode;
|
|
860
|
-
(function (ApiErrorCode) {
|
|
861
|
-
ApiErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
862
|
-
ApiErrorCode["API_REQUEST_FAILED"] = "API_REQUEST_FAILED";
|
|
863
|
-
ApiErrorCode["INVALID_RESPONSE"] = "INVALID_RESPONSE";
|
|
864
|
-
ApiErrorCode["MISSING_API_KEY"] = "MISSING_API_KEY";
|
|
865
|
-
})(ApiErrorCode || (ApiErrorCode = {}));
|
|
866
|
-
/**
|
|
867
|
-
* API error class for better error handling
|
|
868
|
-
*/
|
|
869
|
-
var ApiError = /** @class */ (function (_super) {
|
|
870
|
-
__extends(ApiError, _super);
|
|
871
|
-
function ApiError(message, code, context) {
|
|
872
|
-
if (context === void 0) { context = {}; }
|
|
873
|
-
var _this = _super.call(this, message) || this;
|
|
874
|
-
_this.name = "ApiError";
|
|
875
|
-
_this.code = code;
|
|
876
|
-
_this.context = context;
|
|
877
|
-
return _this;
|
|
878
|
-
}
|
|
879
|
-
return ApiError;
|
|
880
|
-
}(Error));
|
|
881
|
-
/**
|
|
882
|
-
* Fetch chatbot configuration from API
|
|
883
|
-
*/
|
|
884
|
-
var fetchChatbotConfig = function (chatbotId, userId, token) { return __awaiter(void 0, void 0, void 0, function () {
|
|
885
|
-
var apiUrl, endpointUrl, payload, response, errorText, data, error_1;
|
|
886
|
-
var _a;
|
|
887
|
-
return __generator(this, function (_b) {
|
|
888
|
-
switch (_b.label) {
|
|
889
|
-
case 0:
|
|
890
|
-
if (!chatbotId) {
|
|
891
|
-
throw new ApiError("Missing required API key", ApiErrorCode.MISSING_API_KEY, { chatbotId: chatbotId });
|
|
892
|
-
}
|
|
893
|
-
apiUrl = getEnvironmentConfig().apiUrl;
|
|
894
|
-
endpointUrl = "".concat(apiUrl, "/chat/chatbot/get/");
|
|
895
|
-
payload = {
|
|
896
|
-
client_user_id: userId,
|
|
897
|
-
org_id: chatbotId,
|
|
898
|
-
token: token || undefined,
|
|
899
|
-
extra_info: {},
|
|
900
|
-
};
|
|
901
|
-
_b.label = 1;
|
|
902
|
-
case 1:
|
|
903
|
-
_b.trys.push([1, 6, , 7]);
|
|
904
|
-
logger.log("Fetching chatbot config from ".concat(endpointUrl));
|
|
905
|
-
return [4 /*yield*/, fetch(endpointUrl, {
|
|
906
|
-
method: "POST",
|
|
907
|
-
headers: {
|
|
908
|
-
"Content-Type": "application/json",
|
|
909
|
-
},
|
|
910
|
-
body: JSON.stringify(payload),
|
|
911
|
-
})];
|
|
912
|
-
case 2:
|
|
913
|
-
response = _b.sent();
|
|
914
|
-
if (!!response.ok) return [3 /*break*/, 4];
|
|
915
|
-
return [4 /*yield*/, response.text()];
|
|
916
|
-
case 3:
|
|
917
|
-
errorText = _b.sent();
|
|
918
|
-
throw new ApiError("API request failed with status ".concat(response.status, ": ").concat(errorText), ApiErrorCode.API_REQUEST_FAILED, {
|
|
919
|
-
statusCode: response.status,
|
|
920
|
-
errorText: errorText,
|
|
921
|
-
payload: payload,
|
|
922
|
-
});
|
|
923
|
-
case 4: return [4 /*yield*/, response.json()];
|
|
924
|
-
case 5:
|
|
925
|
-
data = _b.sent();
|
|
926
|
-
// Validate the response structure
|
|
927
|
-
if (!((_a = data === null || data === void 0 ? void 0 : data.user) === null || _a === void 0 ? void 0 : _a.org_info)) {
|
|
928
|
-
throw new ApiError("Invalid API response: missing required fields", ApiErrorCode.INVALID_RESPONSE, {
|
|
929
|
-
missingFields: ["user", "org_info"],
|
|
930
|
-
responseData: data,
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
return [2 /*return*/, data];
|
|
934
|
-
case 6:
|
|
935
|
-
error_1 = _b.sent();
|
|
936
|
-
// If it's already an ApiError, just rethrow it
|
|
937
|
-
if (error_1 instanceof ApiError) {
|
|
938
|
-
throw error_1;
|
|
939
|
-
}
|
|
940
|
-
// Otherwise wrap in a generic network error
|
|
941
|
-
throw new ApiError("Network error: ".concat(error_1 instanceof Error ? error_1.message : String(error_1)), ApiErrorCode.NETWORK_ERROR, {
|
|
942
|
-
chatbotId: chatbotId,
|
|
943
|
-
userId: userId,
|
|
944
|
-
apiUrl: apiUrl,
|
|
945
|
-
originalError: error_1,
|
|
946
|
-
timestamp: Date.now(),
|
|
947
|
-
});
|
|
948
|
-
case 7: return [2 /*return*/];
|
|
949
|
-
}
|
|
950
|
-
});
|
|
951
|
-
}); };
|
|
952
|
-
|
|
953
|
-
/**
|
|
954
|
-
* System information detection utilities
|
|
955
|
-
*/
|
|
956
|
-
// Define the SDK version - this will be updated by the build process
|
|
957
|
-
var SDK_VERSION = "1.0.0";
|
|
958
|
-
/**
|
|
959
|
-
* Detect the operating system from the user agent
|
|
960
|
-
*/
|
|
961
|
-
var detectOS = function () {
|
|
962
|
-
var _a;
|
|
963
|
-
if (typeof navigator === "undefined")
|
|
964
|
-
return "Unknown";
|
|
965
|
-
return (((_a = navigator.userAgentData) === null || _a === void 0 ? void 0 : _a.platform) ||
|
|
966
|
-
(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent) || [
|
|
967
|
-
"Unknown",
|
|
968
|
-
])[0]);
|
|
969
|
-
};
|
|
970
|
-
/**
|
|
971
|
-
* Detect the browser from the user agent
|
|
972
|
-
*/
|
|
973
|
-
var detectBrowser = function () {
|
|
974
|
-
var _a;
|
|
975
|
-
if (typeof navigator === "undefined")
|
|
976
|
-
return "Unknown";
|
|
977
|
-
// Try to get the most relevant brand from userAgentData
|
|
978
|
-
if ((_a = navigator.userAgentData) === null || _a === void 0 ? void 0 : _a.brands) {
|
|
979
|
-
var brands = navigator.userAgentData.brands;
|
|
980
|
-
// Look for known browsers in order of preference
|
|
981
|
-
var knownBrands = ["Chrome", "Firefox", "Safari", "Edge", "Opera"];
|
|
982
|
-
for (var _i = 0, brands_1 = brands; _i < brands_1.length; _i++) {
|
|
983
|
-
var brand = brands_1[_i];
|
|
984
|
-
if (knownBrands.includes(brand.brand)) {
|
|
985
|
-
return brand.brand;
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
// Fallback to userAgent parsing
|
|
990
|
-
return (/Chrome|Firefox|Safari|Edge|Opera/.exec(navigator.userAgent) || [
|
|
991
|
-
"Unknown",
|
|
992
|
-
])[0];
|
|
993
|
-
};
|
|
994
|
-
/**
|
|
995
|
-
* Detect the device type from the user agent
|
|
996
|
-
*/
|
|
997
|
-
var detectDevice = function () {
|
|
998
|
-
if (typeof navigator === "undefined")
|
|
999
|
-
return "Unknown";
|
|
1000
|
-
var userAgent = navigator.userAgent.toLowerCase();
|
|
1001
|
-
if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(userAgent)) {
|
|
1002
|
-
return "tablet";
|
|
1003
|
-
}
|
|
1004
|
-
if (/Mobile|Android|iP(hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(userAgent)) {
|
|
1005
|
-
return "mobile";
|
|
1006
|
-
}
|
|
1007
|
-
return "desktop";
|
|
1008
|
-
};
|
|
1009
|
-
/**
|
|
1010
|
-
* Get the screen dimensions
|
|
1011
|
-
*/
|
|
1012
|
-
var getScreenSize = function () {
|
|
1013
|
-
var _a, _b, _c, _d;
|
|
1014
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
1015
|
-
return { width: 0, height: 0 };
|
|
1016
|
-
}
|
|
1017
|
-
return {
|
|
1018
|
-
width: (window === null || window === void 0 ? void 0 : window.innerWidth) ||
|
|
1019
|
-
((_a = document === null || document === void 0 ? void 0 : document.documentElement) === null || _a === void 0 ? void 0 : _a.clientWidth) ||
|
|
1020
|
-
((_b = document === null || document === void 0 ? void 0 : document.body) === null || _b === void 0 ? void 0 : _b.clientWidth) ||
|
|
1021
|
-
0,
|
|
1022
|
-
height: (window === null || window === void 0 ? void 0 : window.innerHeight) ||
|
|
1023
|
-
((_c = document === null || document === void 0 ? void 0 : document.documentElement) === null || _c === void 0 ? void 0 : _c.clientHeight) ||
|
|
1024
|
-
((_d = document === null || document === void 0 ? void 0 : document.body) === null || _d === void 0 ? void 0 : _d.clientHeight) ||
|
|
1025
|
-
0,
|
|
1026
|
-
};
|
|
1027
|
-
};
|
|
1028
|
-
/**
|
|
1029
|
-
* Get complete system information
|
|
1030
|
-
*/
|
|
1031
|
-
var getSystemInfo = function () {
|
|
1032
|
-
return {
|
|
1033
|
-
platform: "web",
|
|
1034
|
-
os: detectOS(),
|
|
1035
|
-
browser: detectBrowser(),
|
|
1036
|
-
sdk_version: SDK_VERSION,
|
|
1037
|
-
device: detectDevice(),
|
|
1038
|
-
screen_size: getScreenSize(),
|
|
1039
|
-
};
|
|
1040
|
-
};
|
|
1041
|
-
|
|
1042
|
-
/**
|
|
1043
|
-
* Initialize the SDK with custom environment settings
|
|
1044
|
-
* @internal This is primarily for internal use and advanced debugging.
|
|
1045
|
-
* Normal users should not need to call this function.
|
|
1046
|
-
*/
|
|
1047
|
-
function init(config) {
|
|
1048
|
-
// For internal SDK initialization - not intended for general user use
|
|
1049
|
-
// We prioritize built-in environment settings based on NODE_ENV
|
|
1050
|
-
// Get current environment from build-time
|
|
1051
|
-
var currentEnv = "staging" ;
|
|
1052
|
-
// Default environment-specific API URLs
|
|
1053
|
-
var defaultApiUrls = {
|
|
1054
|
-
development: "https://dev-api.robylon.ai",
|
|
1055
|
-
staging: "https://stage-api.robylon.ai",
|
|
1056
|
-
production: "https://api.robylon.ai",
|
|
1057
|
-
};
|
|
1058
|
-
// Default environment-specific Copilot URLs
|
|
1059
|
-
var defaultCopilotUrls = {
|
|
1060
|
-
development: "https://dev.robylon.ai",
|
|
1061
|
-
staging: "https://staging.d2s3wsqyyond1h.amplifyapp.com",
|
|
1062
|
-
production: "https://app.robylon.ai",
|
|
1063
|
-
};
|
|
1064
|
-
// Only override with user values in non-production environments or if explicitly allowed
|
|
1065
|
-
var isProduction = currentEnv === "production";
|
|
1066
|
-
config.allowProductionOverride === "true" && isProduction;
|
|
1067
|
-
{
|
|
1068
|
-
// Use environment-specific defaults as fallbacks
|
|
1069
|
-
var configWithDefaults = __assign(__assign({}, config), { apiUrl: config.apiUrl ||
|
|
1070
|
-
defaultApiUrls[currentEnv], copilotUrl: config.copilotUrl ||
|
|
1071
|
-
defaultCopilotUrls[currentEnv], environment: config.environment || currentEnv });
|
|
1072
|
-
setEnvironmentConfig(configWithDefaults);
|
|
1073
|
-
logger.log("Robylon SDK environment initialized with custom config", configWithDefaults);
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
/**
|
|
1077
|
-
* Create a new Robylon chatbot instance
|
|
1078
|
-
*/
|
|
1079
|
-
function create(config) {
|
|
1080
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1081
|
-
var userId, isAnonymous, systemInfo_1, apiResponse, userProfile, chatbotConfig, chatbotEmbed_1, error_1;
|
|
1082
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1083
|
-
return __generator(this, function (_h) {
|
|
1084
|
-
switch (_h.label) {
|
|
1085
|
-
case 0:
|
|
1086
|
-
if (!config.api_key) {
|
|
1087
|
-
throw new Error("api_key is required to create a chatbot instance");
|
|
1088
|
-
}
|
|
1089
|
-
_h.label = 1;
|
|
1090
|
-
case 1:
|
|
1091
|
-
_h.trys.push([1, 3, , 4]);
|
|
1092
|
-
userId = config.user_id;
|
|
1093
|
-
isAnonymous = false;
|
|
1094
|
-
// Handle anonymous users
|
|
1095
|
-
if (!userId) {
|
|
1096
|
-
userId = getCookie("rblyn_anon") || generateUUID();
|
|
1097
|
-
setCookie("rblyn_anon", String(userId), 365);
|
|
1098
|
-
isAnonymous = true;
|
|
1099
|
-
}
|
|
1100
|
-
systemInfo_1 = getSystemInfo();
|
|
1101
|
-
return [4 /*yield*/, fetchChatbotConfig(config.api_key, userId, config.user_token)];
|
|
1102
|
-
case 2:
|
|
1103
|
-
apiResponse = _h.sent();
|
|
1104
|
-
userProfile = __assign(__assign({}, systemInfo_1), config.user_profile);
|
|
1105
|
-
chatbotConfig = {
|
|
1106
|
-
chatbotId: config.api_key,
|
|
1107
|
-
userId: userId,
|
|
1108
|
-
token: config.user_token,
|
|
1109
|
-
isAnonymous: isAnonymous,
|
|
1110
|
-
domain: getEnvironmentConfig().copilotUrl,
|
|
1111
|
-
brand_colour: ((_b = (_a = apiResponse.user.org_info.brand_config) === null || _a === void 0 ? void 0 : _a.colors) === null || _b === void 0 ? void 0 : _b.brand_color) ||
|
|
1112
|
-
"#6a26cd",
|
|
1113
|
-
image_url: ((_d = (_c = apiResponse.user.org_info) === null || _c === void 0 ? void 0 : _c.brand_config) === null || _d === void 0 ? void 0 : _d.launcher_logo_url) || "",
|
|
1114
|
-
userProfile: userProfile,
|
|
1115
|
-
chat_interface_config: {
|
|
1116
|
-
chat_bubble_prompts: [],
|
|
1117
|
-
display_name: ((_e = apiResponse.user.org_info.brand_config) === null || _e === void 0 ? void 0 : _e.display_name) || "",
|
|
1118
|
-
welcome_message: ((_f = apiResponse.user.org_info.brand_config) === null || _f === void 0 ? void 0 : _f.welcome_message) ||
|
|
1119
|
-
"Hey! What can we help you with today?",
|
|
1120
|
-
redirect_url: ((_g = apiResponse.user.org_info.brand_config) === null || _g === void 0 ? void 0 : _g.redirect_url) || "",
|
|
1121
|
-
},
|
|
1122
|
-
};
|
|
1123
|
-
chatbotEmbed_1 = new ChatbotEmbed(chatbotConfig);
|
|
1124
|
-
// Set up event handler
|
|
1125
|
-
if (config.onEvent) {
|
|
1126
|
-
chatbotEmbed_1.on("*", config.onEvent);
|
|
1127
|
-
}
|
|
1128
|
-
// Return public API
|
|
1129
|
-
return [2 /*return*/, {
|
|
1130
|
-
show: function () { return chatbotEmbed_1.show(); },
|
|
1131
|
-
hide: function () { return chatbotEmbed_1.hide(); },
|
|
1132
|
-
toggle: function () { return chatbotEmbed_1.toggle(); },
|
|
1133
|
-
update: function (newConfig) {
|
|
1134
|
-
// Handle profile updates
|
|
1135
|
-
if (newConfig.user_profile) {
|
|
1136
|
-
chatbotEmbed_1.updateConfig({
|
|
1137
|
-
userProfile: __assign(__assign({}, systemInfo_1), newConfig.user_profile),
|
|
1138
|
-
});
|
|
1139
|
-
}
|
|
1140
|
-
// Handle user_id updates
|
|
1141
|
-
if (newConfig.user_id !== undefined) {
|
|
1142
|
-
chatbotEmbed_1.updateConfig({
|
|
1143
|
-
userId: newConfig.user_id ? String(newConfig.user_id) : null,
|
|
1144
|
-
});
|
|
1145
|
-
}
|
|
1146
|
-
// Handle token updates
|
|
1147
|
-
if (newConfig.user_token !== undefined) {
|
|
1148
|
-
chatbotEmbed_1.updateConfig({
|
|
1149
|
-
token: newConfig.user_token,
|
|
1150
|
-
});
|
|
1151
|
-
}
|
|
1152
|
-
},
|
|
1153
|
-
destroy: function () { return chatbotEmbed_1.destroy(); },
|
|
1154
|
-
}];
|
|
1155
|
-
case 3:
|
|
1156
|
-
error_1 = _h.sent();
|
|
1157
|
-
logger.error("Failed to create chatbot instance:", error_1);
|
|
1158
|
-
if (error_1 instanceof ApiError) {
|
|
1159
|
-
throw new Error("Robylon SDK initialization failed: ".concat(error_1.message, " (").concat(error_1.code, ")"));
|
|
1160
|
-
}
|
|
1161
|
-
throw new Error("Robylon SDK initialization failed: ".concat(error_1 instanceof Error ? error_1.message : String(error_1)));
|
|
1162
|
-
case 4: return [2 /*return*/];
|
|
1163
|
-
}
|
|
1164
|
-
});
|
|
1165
|
-
});
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
// Conditionally import React components to avoid errors in environments without React
|
|
1169
|
-
var RobylonChatbot = null;
|
|
1170
|
-
// Try to import React components, but don't fail if React is not available
|
|
1171
|
-
try {
|
|
1172
|
-
// Import React components
|
|
1173
|
-
var ReactImports = require("./react/components/Chatbot");
|
|
1174
|
-
RobylonChatbot = ReactImports.default || ReactImports.Chatbot;
|
|
1175
|
-
}
|
|
1176
|
-
catch (e) {
|
|
1177
|
-
// React not available, provide a placeholder
|
|
1178
|
-
RobylonChatbot = function () {
|
|
1179
|
-
throw new Error("React is required to use the Chatbot component");
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
// Export the Chatbot component for compatibility if available
|
|
1183
|
-
var Chatbot = RobylonChatbot;
|
|
1184
|
-
// Expose the public API
|
|
1185
|
-
var Robylon = {
|
|
1186
|
-
/**
|
|
1187
|
-
* Create a new Robylon chatbot instance
|
|
1188
|
-
*/
|
|
1189
|
-
create: create,
|
|
1190
|
-
/**
|
|
1191
|
-
* Initialize the SDK with custom environment settings
|
|
1192
|
-
*/
|
|
1193
|
-
init: init,
|
|
1194
|
-
/**
|
|
1195
|
-
* The Chatbot React component
|
|
1196
|
-
*/
|
|
1197
|
-
Chatbot: RobylonChatbot,
|
|
1198
|
-
/**
|
|
1199
|
-
* Configure logging
|
|
1200
|
-
*/
|
|
1201
|
-
logging: {
|
|
1202
|
-
/**
|
|
1203
|
-
* Enable or disable logging
|
|
1204
|
-
*/
|
|
1205
|
-
setEnabled: function (enabled) { return logger.setEnabled(enabled); },
|
|
1206
|
-
/**
|
|
1207
|
-
* Set log level
|
|
1208
|
-
*/
|
|
1209
|
-
setLevel: function (level) {
|
|
1210
|
-
return logger.setLevel(level);
|
|
1211
|
-
},
|
|
1212
|
-
},
|
|
1213
|
-
};
|
|
1214
|
-
// For UMD/global environments
|
|
1215
|
-
if (typeof window !== "undefined") {
|
|
1216
|
-
window.Robylon = Robylon;
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
exports.Chatbot = Chatbot;
|
|
1220
|
-
exports.create = create;
|
|
1221
|
-
exports.default = Robylon;
|
|
1222
|
-
exports.init = init;
|
|
1223
|
-
|
|
1224
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
exports.Chatbot = Robylon.Chatbot; // Ensure Chatbot is accessible
|
|
1228
|
-
|
|
1229
|
-
}));
|
|
1230
|
-
//# sourceMappingURL=robylon.js.map
|