@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@product7/product7-js",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "JavaScript SDK for integrating Product7 feedback widgets into any website",
5
5
  "main": "dist/product7-js.js",
6
6
  "module": "src/index.js",
@@ -17,6 +17,7 @@ import { PreChatFormView } from './messenger/views/PreChatFormView.js';
17
17
  export class MessengerWidget extends BaseWidget {
18
18
  constructor(options) {
19
19
  super({ ...options, type: 'messenger' });
20
+ this._explicitOptions = options || {};
20
21
  const resolvedTheme = options.theme || 'light';
21
22
  const hasExplicitTextColor = Object.prototype.hasOwnProperty.call(
22
23
  options,
@@ -287,6 +288,11 @@ export class MessengerWidget extends BaseWidget {
287
288
  name: contactData.name,
288
289
  email: contactData.email,
289
290
  });
291
+
292
+ // Start WebSocket now that session token is available
293
+ if (this.apiService?.sessionToken && !this.wsService?.isConnected) {
294
+ this._initWebSocket();
295
+ }
290
296
  }
291
297
 
292
298
  return response;
@@ -299,6 +305,11 @@ export class MessengerWidget extends BaseWidget {
299
305
  markAsIdentified(name, email) {
300
306
  this.messengerState.setIdentified(true, { name, email });
301
307
  console.log('[MessengerWidget] Marked as identified:', email);
308
+
309
+ // Start WebSocket now that we have a session token
310
+ if (this.apiService?.sessionToken && !this.wsService?.isConnected) {
311
+ this._initWebSocket();
312
+ }
302
313
  }
303
314
 
304
315
  async _handleUploadFile(base64Data, filename) {
@@ -809,6 +820,39 @@ export class MessengerWidget extends BaseWidget {
809
820
  }
810
821
  }
811
822
 
823
+ async _fetchAndApplySettings() {
824
+ try {
825
+ const response = await this.apiService.getMessengerSettings();
826
+ if (!response?.status || !response?.data) return;
827
+
828
+ const s = response.data;
829
+
830
+ // Only apply values that were NOT explicitly passed in options
831
+ if (s.team_name && !this._hasExplicitOption('teamName')) {
832
+ this.messengerOptions.teamName = s.team_name;
833
+ this.messengerState.teamName = s.team_name;
834
+ }
835
+ if (s.logo_url && !this._hasExplicitOption('logoUrl')) {
836
+ this.messengerOptions.logoUrl = s.logo_url;
837
+ }
838
+ if (s.greeting_message && !this._hasExplicitOption('greetingMessage')) {
839
+ this.messengerState.greetingMessage = s.greeting_message;
840
+ }
841
+ if (s.response_time && !this._hasExplicitOption('responseTime')) {
842
+ this.messengerState.responseTime = s.response_time;
843
+ }
844
+
845
+ // Notify views to re-render with new values
846
+ this.messengerState._notify('availabilityUpdate', {});
847
+ } catch (e) {
848
+ // non-fatal
849
+ }
850
+ }
851
+
852
+ _hasExplicitOption(key) {
853
+ return Object.prototype.hasOwnProperty.call(this._explicitOptions || {}, key);
854
+ }
855
+
812
856
  async checkAgentAvailability() {
813
857
  try {
814
858
  const response = await this.apiService.checkAgentsOnline();
@@ -954,6 +998,9 @@ export class MessengerWidget extends BaseWidget {
954
998
  this._applyPreviewData();
955
999
 
956
1000
  if (this.messengerOptions.autoLoadData) {
1001
+ // Fetch workspace settings and apply only if not explicitly configured
1002
+ this._fetchAndApplySettings();
1003
+
957
1004
  this.loadInitialData();
958
1005
 
959
1006
  if (this.apiService?.sessionToken) {