@robylon/web-react-sdk 1.1.28-staging.58 → 1.1.28-staging.59

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 CHANGED
@@ -13,7 +13,7 @@ npm install @robylon/web-react-sdk
13
13
  ### Vanilla JavaScript
14
14
 
15
15
  ```html
16
- <script src="https://staging-cdn.robylon.com/1.1.28-staging.57/robylon.min.js"></script>
16
+ <script src="https://staging-cdn.robylon.com/1.1.28-staging.58/robylon.min.js"></script>
17
17
  ```
18
18
 
19
19
  Or via npm:
package/dist/cjs/index.js CHANGED
@@ -454,35 +454,41 @@ var ChatbotEmbed = /** @class */ (function () {
454
454
  var _this = this;
455
455
  var div = document.createElement("div");
456
456
  div.classList.add("message-bubble-container");
457
- Object.assign(div.style, {
458
- position: "fixed", // Use fixed positioning
459
- bottom: "1.5rem",
460
- right: "1.5rem",
461
- zIndex: "1000",
462
- width: "48px",
463
- height: "48px",
464
- display: "flex",
465
- flexDirection: "column-reverse",
466
- backgroundColor: this.config.brand_colour,
467
- color: getBestFontColor(this.config.brand_colour),
468
- borderRadius: "50%",
469
- alignItems: "center",
470
- justifyContent: "center",
471
- cursor: "pointer",
472
- overflow: "hidden",
457
+ // Force styles with !important to override any potential conflicts
458
+ div.setAttribute("style", "\n position: fixed !important;\n bottom: 20px !important;\n right: 20px !important;\n z-index: 2147483647 !important;\n width: 60px !important;\n height: 60px !important;\n display: flex !important;\n flex-direction: column-reverse !important;\n background-color: ".concat(this.config.brand_colour, " !important;\n color: ").concat(getBestFontColor(this.config.brand_colour), " !important;\n border-radius: 50% !important;\n align-items: center !important;\n justify-content: center !important;\n cursor: pointer !important;\n overflow: hidden !important;\n box-shadow: 0 4px 8px rgba(0,0,0,0.2) !important;\n "));
459
+ // Explicitly log button creation
460
+ console.log("ROBYLON DEBUG: Creating button", {
461
+ time: new Date().toISOString(),
462
+ color: this.config.brand_colour,
473
463
  });
474
- // Always append to document.body for consistent positioning
464
+ // Always append to body
475
465
  document.body.appendChild(div);
476
466
  this.logoContainer = div;
477
467
  this.loadImage(this.logoContainer);
478
468
  this.createChatBubblContainer();
479
- this.logoContainer.addEventListener("click", this.toggleIframe.bind(this));
480
- // Setup visibility observer
481
- this.setupContainerVisibilityObserver();
482
- // Emit button loaded event
469
+ // Ensure button is clickable
470
+ this.logoContainer.addEventListener("click", function () {
471
+ console.log("ROBYLON DEBUG: Button clicked");
472
+ _this.toggleIframe();
473
+ });
474
+ // Add a backup timeout to check button visibility
483
475
  setTimeout(function () {
484
- _this.emit("CHATBOT_BUTTON_LOADED");
485
- }, 0);
476
+ if (_this.logoContainer) {
477
+ console.log("ROBYLON DEBUG: Button visibility check", {
478
+ exists: !!_this.logoContainer,
479
+ isConnected: _this.logoContainer.isConnected,
480
+ offsetParent: !!_this.logoContainer.offsetParent,
481
+ computedDisplay: window === null || window === void 0 ? void 0 : window.getComputedStyle(_this.logoContainer).display,
482
+ rect: _this.logoContainer.getBoundingClientRect(),
483
+ });
484
+ // Force visibility again if needed
485
+ if ((window === null || window === void 0 ? void 0 : window.getComputedStyle(_this.logoContainer).display) === "none") {
486
+ _this.logoContainer.style.display = "flex !important";
487
+ }
488
+ }
489
+ }, 1000);
490
+ // Emit button loaded event
491
+ this.emit("CHATBOT_BUTTON_LOADED");
486
492
  };
487
493
  ChatbotEmbed.prototype.createChatBubblContainer = function () {
488
494
  var _this = this;
@@ -669,19 +675,26 @@ var ChatbotEmbed = /** @class */ (function () {
669
675
  };
670
676
  ChatbotEmbed.prototype.loadImage = function (containerElement) {
671
677
  var image = document.createElement("img");
678
+ // Log image loading
679
+ console.log("ROBYLON DEBUG: Loading image", {
680
+ src: this.config.image_url || "".concat(this.config.domain, "/chatbubble.png"),
681
+ });
672
682
  image.src = this.config.image_url || "".concat(this.config.domain, "/chatbubble.png");
673
683
  image.alt = "Chat";
674
- Object.assign(image.style, {
675
- zIndex: "1000",
676
- cursor: "pointer",
677
- borderRadius: "50%",
678
- objectFit: "cover",
679
- width: "100%",
680
- height: "100%",
681
- });
684
+ // Force image visibility
685
+ image.setAttribute("style", "\n z-index: 2147483647 !important;\n cursor: pointer !important;\n border-radius: 50% !important;\n object-fit: cover !important;\n width: 100% !important;\n height: 100% !important;\n display: block !important;\n ");
682
686
  this.chatBtnImage = image;
683
687
  containerElement.innerHTML = ""; // Clear any existing content
684
688
  containerElement.appendChild(image);
689
+ // Add image load error handling
690
+ image.onerror = function (err) {
691
+ console.error("ROBYLON DEBUG: Image failed to load", {
692
+ src: image.src,
693
+ error: err,
694
+ });
695
+ // Add fallback content
696
+ containerElement.innerHTML = "Chat";
697
+ };
685
698
  };
686
699
  ChatbotEmbed.prototype.loadSvgInline = function (containerElement) {
687
700
  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";
@@ -1207,80 +1220,109 @@ var RobylonChatbot = React.memo(function (_a) {
1207
1220
  }, [onEvent]);
1208
1221
  // Initialize the chatbot
1209
1222
  var initializeChatbot = React.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
1210
- var userId, isAnonymous, apiResponse, systemInfo, finalUserProfile, config, err_1, errorMessage;
1211
- var _a, _b, _c, _d, _e, _f, _g;
1212
- return __generator(this, function (_h) {
1213
- switch (_h.label) {
1223
+ var tryInitialize;
1224
+ return __generator(this, function (_a) {
1225
+ switch (_a.label) {
1214
1226
  case 0:
1215
1227
  if (!api_key) {
1216
1228
  setError("API key is required");
1229
+ console.error("ROBYLON DEBUG: API key is required");
1217
1230
  return [2 /*return*/];
1218
1231
  }
1219
- if (isInitializing || isInitialized)
1232
+ if (isInitializing || isInitialized) {
1233
+ console.log("ROBYLON DEBUG: Already initializing or initialized");
1220
1234
  return [2 /*return*/];
1221
- setIsInitializing(true);
1222
- _h.label = 1;
1223
- case 1:
1224
- _h.trys.push([1, 3, 4, 5]);
1225
- userId = user_id;
1226
- isAnonymous = false;
1227
- // Handle anonymous users
1228
- if (!userId) {
1229
- userId = getCookie("rblyn_anon") || generateUUID();
1230
- setCookie("rblyn_anon", String(userId), 365);
1231
- isAnonymous = true;
1232
1235
  }
1233
- return [4 /*yield*/, fetchChatbotConfig(api_key, userId, user_token)];
1234
- case 2:
1235
- apiResponse = _h.sent();
1236
- systemInfo = getSystemInfo();
1237
- finalUserProfile = __assign(__assign({}, systemInfo), user_profile);
1238
- config = {
1239
- chatbotId: api_key,
1240
- userId: userId ? String(userId) : null,
1241
- token: user_token,
1242
- isAnonymous: isAnonymous,
1243
- domain: getEnvironmentConfig().copilotUrl,
1244
- 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) ||
1245
- "#6a26cd",
1246
- 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) || "",
1247
- userProfile: finalUserProfile,
1248
- chat_interface_config: {
1249
- chat_bubble_prompts: [],
1250
- display_name: ((_e = apiResponse.user.org_info.brand_config) === null || _e === void 0 ? void 0 : _e.display_name) || "",
1251
- welcome_message: ((_f = apiResponse.user.org_info.brand_config) === null || _f === void 0 ? void 0 : _f.welcome_message) ||
1252
- "Hey! What can we help you with today?",
1253
- redirect_url: ((_g = apiResponse.user.org_info.brand_config) === null || _g === void 0 ? void 0 : _g.redirect_url) || "",
1254
- },
1255
- };
1256
- // Store the config
1257
- setChatbotConfig(config);
1258
- // CRITICAL CHANGE: Pass container element to ChatbotEmbed
1259
- if (containerRef.current) {
1260
- chatbotRef.current = new ChatbotEmbed(config, {
1261
- containerElement: containerRef.current,
1236
+ setIsInitializing(true);
1237
+ console.log("ROBYLON DEBUG: Starting initialization");
1238
+ tryInitialize = function () {
1239
+ var args_1 = [];
1240
+ for (var _i = 0; _i < arguments.length; _i++) {
1241
+ args_1[_i] = arguments[_i];
1242
+ }
1243
+ return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (attempt) {
1244
+ var userId, isAnonymous, apiResponse, systemInfo, finalUserProfile, config, err_1, errorMessage;
1245
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1246
+ if (attempt === void 0) { attempt = 1; }
1247
+ return __generator(this, function (_j) {
1248
+ switch (_j.label) {
1249
+ case 0:
1250
+ _j.trys.push([0, 2, , 3]);
1251
+ userId = user_id;
1252
+ isAnonymous = false;
1253
+ // Handle anonymous users
1254
+ if (!userId) {
1255
+ userId = getCookie("rblyn_anon") || generateUUID();
1256
+ setCookie("rblyn_anon", String(userId), 365);
1257
+ isAnonymous = true;
1258
+ }
1259
+ console.log("ROBYLON DEBUG: Fetching chatbot config", {
1260
+ userId: userId,
1261
+ isAnonymous: isAnonymous,
1262
+ });
1263
+ return [4 /*yield*/, fetchChatbotConfig(api_key, userId, user_token)];
1264
+ case 1:
1265
+ apiResponse = _j.sent();
1266
+ console.log("ROBYLON DEBUG: API response received", {
1267
+ success: !!apiResponse,
1268
+ hasOrgInfo: !!((_a = apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.user) === null || _a === void 0 ? void 0 : _a.org_info),
1269
+ });
1270
+ systemInfo = getSystemInfo();
1271
+ finalUserProfile = __assign(__assign({}, systemInfo), user_profile);
1272
+ config = {
1273
+ chatbotId: api_key,
1274
+ userId: userId ? String(userId) : null,
1275
+ token: user_token,
1276
+ isAnonymous: isAnonymous,
1277
+ domain: getEnvironmentConfig().copilotUrl,
1278
+ brand_colour: ((_c = (_b = apiResponse.user.org_info.brand_config) === null || _b === void 0 ? void 0 : _b.colors) === null || _c === void 0 ? void 0 : _c.brand_color) ||
1279
+ "#6a26cd",
1280
+ image_url: ((_e = (_d = apiResponse.user.org_info) === null || _d === void 0 ? void 0 : _d.brand_config) === null || _e === void 0 ? void 0 : _e.launcher_logo_url) || "",
1281
+ userProfile: finalUserProfile,
1282
+ chat_interface_config: {
1283
+ chat_bubble_prompts: [],
1284
+ display_name: ((_f = apiResponse.user.org_info.brand_config) === null || _f === void 0 ? void 0 : _f.display_name) || "",
1285
+ welcome_message: ((_g = apiResponse.user.org_info.brand_config) === null || _g === void 0 ? void 0 : _g.welcome_message) ||
1286
+ "Hey! What can we help you with today?",
1287
+ redirect_url: ((_h = apiResponse.user.org_info.brand_config) === null || _h === void 0 ? void 0 : _h.redirect_url) || "",
1288
+ },
1289
+ };
1290
+ // Store the config
1291
+ setChatbotConfig(config);
1292
+ console.log("ROBYLON DEBUG: Creating ChatbotEmbed instance", config);
1293
+ // Create the chatbot instance and always use document.body first
1294
+ chatbotRef.current = new ChatbotEmbed(config);
1295
+ // Register event handler
1296
+ if (stableOnEvent) {
1297
+ chatbotRef.current.on("*", stableOnEvent);
1298
+ }
1299
+ setIsInitialized(true);
1300
+ console.log("ROBYLON DEBUG: Initialization complete");
1301
+ return [3 /*break*/, 3];
1302
+ case 2:
1303
+ err_1 = _j.sent();
1304
+ errorMessage = err_1 instanceof Error ? err_1.message : "Failed to initialize chatbot";
1305
+ console.error("ROBYLON DEBUG: Error during initialization (attempt ".concat(attempt, ")"), err_1);
1306
+ // Retry up to 3 times with increasing delay
1307
+ if (attempt < 3) {
1308
+ console.log("ROBYLON DEBUG: Retrying initialization (attempt ".concat(attempt + 1, ")"));
1309
+ setTimeout(function () { return tryInitialize(attempt + 1); }, attempt * 1000);
1310
+ }
1311
+ else {
1312
+ setError(errorMessage);
1313
+ logger.error("Chatbot initialization failed:", err_1);
1314
+ }
1315
+ return [3 /*break*/, 3];
1316
+ case 3: return [2 /*return*/];
1317
+ }
1318
+ });
1262
1319
  });
1263
- }
1264
- else {
1265
- // Fallback to body if container not available
1266
- chatbotRef.current = new ChatbotEmbed(config);
1267
- }
1268
- // Register event handler
1269
- if (stableOnEvent) {
1270
- chatbotRef.current.on("*", stableOnEvent);
1271
- }
1272
- setIsInitialized(true);
1273
- return [3 /*break*/, 5];
1274
- case 3:
1275
- err_1 = _h.sent();
1276
- errorMessage = err_1 instanceof Error ? err_1.message : "Failed to initialize chatbot";
1277
- setError(errorMessage);
1278
- logger.error("Chatbot initialization failed:", err_1);
1279
- return [3 /*break*/, 5];
1280
- case 4:
1320
+ };
1321
+ return [4 /*yield*/, tryInitialize()];
1322
+ case 1:
1323
+ _a.sent();
1281
1324
  setIsInitializing(false);
1282
- return [7 /*endfinally*/];
1283
- case 5: return [2 /*return*/];
1325
+ return [2 /*return*/];
1284
1326
  }
1285
1327
  });
1286
1328
  }); }, [
@@ -1290,14 +1332,27 @@ var RobylonChatbot = React.memo(function (_a) {
1290
1332
  stableOnEvent,
1291
1333
  isInitialized,
1292
1334
  isInitializing,
1335
+ user_profile,
1293
1336
  ]);
1294
1337
  // Initialize on component mount
1295
1338
  React.useEffect(function () {
1339
+ // Add explicit debugging
1340
+ console.log("ROBYLON DEBUG: Initializing React component", {
1341
+ apiKeyProvided: !!api_key,
1342
+ userIdProvided: !!user_id,
1343
+ });
1296
1344
  if (api_key) {
1297
- initializeChatbot();
1345
+ // Force immediate initialization
1346
+ try {
1347
+ initializeChatbot();
1348
+ }
1349
+ catch (err) {
1350
+ console.error("ROBYLON DEBUG: Initialization error", err);
1351
+ }
1298
1352
  }
1299
1353
  // Cleanup on unmount
1300
1354
  return function () {
1355
+ console.log("ROBYLON DEBUG: Cleaning up React component");
1301
1356
  if (chatbotRef.current) {
1302
1357
  chatbotRef.current.destroy();
1303
1358
  chatbotRef.current = null;
@@ -1330,11 +1385,14 @@ var RobylonChatbot = React.memo(function (_a) {
1330
1385
  }, [user_profile, isInitialized, chatbotConfig]);
1331
1386
  // CRITICAL CHANGE: Return a minimal container div
1332
1387
  return (jsxRuntime.jsx("div", { ref: containerRef, className: "robylon-chatbot-container", style: {
1333
- width: "0",
1334
- height: "0",
1335
- overflow: "visible",
1336
- display: "inline-block",
1337
- } }));
1388
+ display: "block",
1389
+ position: "fixed",
1390
+ bottom: 0,
1391
+ right: 0,
1392
+ width: "1px",
1393
+ height: "1px",
1394
+ pointerEvents: "none",
1395
+ }, "data-testid": "robylon-chatbot" }));
1338
1396
  }, function (prevProps, nextProps) {
1339
1397
  // Memoization comparison
1340
1398
  return (prevProps.api_key === nextProps.api_key &&