@product7/feedback-sdk 1.3.2 → 1.3.3

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.
@@ -5857,44 +5857,60 @@
5857
5857
  }
5858
5858
  }
5859
5859
 
5860
- async _handleStartConversation(messageContent, pendingAttachments) {
5861
- try {
5862
- const userContext = this.messengerState.userContext;
5863
- const isIdentified = userContext?.email;
5860
+ async _handleStartConversation(messageContent, pendingAttachments) {
5861
+ try {
5862
+ const userContext = this.messengerState.userContext;
5863
+ const isAuthenticated = userContext?.email && userContext?.name;
5864
5864
 
5865
- if (!isIdentified) {
5866
- this.messengerState.pendingMessage = {
5867
- content: messageContent,
5868
- attachments: pendingAttachments,
5869
- };
5870
- this.messengerState.setView('prechat');
5871
- return null;
5865
+ // If user is authenticated, silently identify them first
5866
+ if (isAuthenticated) {
5867
+ try {
5868
+ await this.apiService.identifyContact({
5869
+ name: userContext.name,
5870
+ email: userContext.email,
5871
+ });
5872
+ console.log('[MessengerWidget] User auto-identified for conversation');
5873
+ } catch (error) {
5874
+ // If identification fails with a non-critical error, continue anyway
5875
+ if (error?.code !== 'ALREADY_IDENTIFIED') {
5876
+ console.warn('[MessengerWidget] Auto-identification failed:', error);
5877
+ }
5872
5878
  }
5879
+ } else {
5880
+ // Unauthenticated user - show pre-chat form
5881
+ this.messengerState.pendingMessage = {
5882
+ content: messageContent,
5883
+ attachments: pendingAttachments,
5884
+ };
5885
+ this.messengerState.setView('prechat');
5886
+ return null;
5887
+ }
5873
5888
 
5874
- const openConversation = this.messengerState.conversations.find(
5875
- (c) => c.status === 'open'
5876
- );
5877
-
5878
- if (openConversation) {
5879
- this.messengerState.setActiveConversation(openConversation.id);
5880
- await this._handleSendMessage(
5881
- openConversation.id,
5882
- { content: messageContent },
5883
- pendingAttachments
5884
- );
5885
- return openConversation;
5886
- }
5889
+ // Check for existing open conversation
5890
+ const openConversation = this.messengerState.conversations.find(
5891
+ (c) => c.status === 'open'
5892
+ );
5887
5893
 
5888
- return await this.startNewConversation(
5889
- messageContent,
5890
- '',
5894
+ if (openConversation) {
5895
+ this.messengerState.setActiveConversation(openConversation.id);
5896
+ await this._handleSendMessage(
5897
+ openConversation.id,
5898
+ { content: messageContent },
5891
5899
  pendingAttachments
5892
5900
  );
5893
- } catch (error) {
5894
- console.error('[MessengerWidget] Failed to start conversation:', error);
5895
- return null;
5901
+ return openConversation;
5896
5902
  }
5903
+
5904
+ return await this.startNewConversation(
5905
+ messageContent,
5906
+ '',
5907
+ pendingAttachments
5908
+ );
5909
+ } catch (error) {
5910
+ console.error('[MessengerWidget] Failed to start conversation:', error);
5911
+ return null;
5897
5912
  }
5913
+ }
5898
5914
 
5899
5915
  async _handleSelectConversation(conversationId) {
5900
5916
  try {
@@ -6516,34 +6532,19 @@
6516
6532
  };
6517
6533
  }
6518
6534
 
6519
- async onMount() {
6520
- const userContext = this.messengerState.userContext;
6521
- if (userContext?.email && userContext?.name) {
6522
- try {
6523
- await this.apiService.identifyContact({
6524
- name: userContext.name,
6525
- email: userContext.email,
6526
- });
6527
- console.log('[MessengerWidget] User identified successfully');
6528
- } catch (error) {
6529
- if (error?.code !== 'ALREADY_IDENTIFIED') {
6530
- console.warn('[MessengerWidget] Identification failed:', error);
6531
- }
6532
- }
6533
- }
6535
+ async onMount() {
6536
+ this.loadInitialData();
6534
6537
 
6535
- this.loadInitialData();
6538
+ if (this.apiService?.sessionToken) {
6539
+ this._initWebSocket();
6540
+ }
6536
6541
 
6537
- if (this.apiService?.sessionToken) {
6538
- this._initWebSocket();
6539
- }
6542
+ this.checkAgentAvailability();
6540
6543
 
6544
+ this._availabilityInterval = setInterval(() => {
6541
6545
  this.checkAgentAvailability();
6542
-
6543
- this._availabilityInterval = setInterval(() => {
6544
- this.checkAgentAvailability();
6545
- }, 60000);
6546
- }
6546
+ }, 60000);
6547
+ }
6547
6548
 
6548
6549
  onDestroy() {
6549
6550
  if (this._stateUnsubscribe) {