@product7/product7-js 0.3.1 → 0.3.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.
@@ -11243,6 +11243,7 @@
11243
11243
  class MessengerWidget extends BaseWidget {
11244
11244
  constructor(options) {
11245
11245
  super({ ...options, type: 'messenger' });
11246
+ this._explicitOptions = options || {};
11246
11247
  const resolvedTheme = options.theme || 'light';
11247
11248
  const hasExplicitTextColor = Object.prototype.hasOwnProperty.call(
11248
11249
  options,
@@ -11513,6 +11514,11 @@
11513
11514
  name: contactData.name,
11514
11515
  email: contactData.email,
11515
11516
  });
11517
+
11518
+ // Start WebSocket now that session token is available
11519
+ if (this.apiService?.sessionToken && !this.wsService?.isConnected) {
11520
+ this._initWebSocket();
11521
+ }
11516
11522
  }
11517
11523
 
11518
11524
  return response;
@@ -11525,6 +11531,11 @@
11525
11531
  markAsIdentified(name, email) {
11526
11532
  this.messengerState.setIdentified(true, { name, email });
11527
11533
  console.log('[MessengerWidget] Marked as identified:', email);
11534
+
11535
+ // Start WebSocket now that we have a session token
11536
+ if (this.apiService?.sessionToken && !this.wsService?.isConnected) {
11537
+ this._initWebSocket();
11538
+ }
11528
11539
  }
11529
11540
 
11530
11541
  async _handleUploadFile(base64Data, filename) {
@@ -12035,6 +12046,39 @@
12035
12046
  }
12036
12047
  }
12037
12048
 
12049
+ async _fetchAndApplySettings() {
12050
+ try {
12051
+ const response = await this.apiService.getMessengerSettings();
12052
+ if (!response?.status || !response?.data) return;
12053
+
12054
+ const s = response.data;
12055
+
12056
+ // Only apply values that were NOT explicitly passed in options
12057
+ if (s.team_name && !this._hasExplicitOption('teamName')) {
12058
+ this.messengerOptions.teamName = s.team_name;
12059
+ this.messengerState.teamName = s.team_name;
12060
+ }
12061
+ if (s.logo_url && !this._hasExplicitOption('logoUrl')) {
12062
+ this.messengerOptions.logoUrl = s.logo_url;
12063
+ }
12064
+ if (s.greeting_message && !this._hasExplicitOption('greetingMessage')) {
12065
+ this.messengerState.greetingMessage = s.greeting_message;
12066
+ }
12067
+ if (s.response_time && !this._hasExplicitOption('responseTime')) {
12068
+ this.messengerState.responseTime = s.response_time;
12069
+ }
12070
+
12071
+ // Notify views to re-render with new values
12072
+ this.messengerState._notify('availabilityUpdate', {});
12073
+ } catch (e) {
12074
+ // non-fatal
12075
+ }
12076
+ }
12077
+
12078
+ _hasExplicitOption(key) {
12079
+ return Object.prototype.hasOwnProperty.call(this._explicitOptions || {}, key);
12080
+ }
12081
+
12038
12082
  async checkAgentAvailability() {
12039
12083
  try {
12040
12084
  const response = await this.apiService.checkAgentsOnline();
@@ -12180,6 +12224,9 @@
12180
12224
  this._applyPreviewData();
12181
12225
 
12182
12226
  if (this.messengerOptions.autoLoadData) {
12227
+ // Fetch workspace settings and apply only if not explicitly configured
12228
+ this._fetchAndApplySettings();
12229
+
12183
12230
  this.loadInitialData();
12184
12231
 
12185
12232
  if (this.apiService?.sessionToken) {