@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.
package/package.json
CHANGED
|
@@ -132,44 +132,60 @@ export class MessengerWidget extends BaseWidget {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
async _handleStartConversation(messageContent, pendingAttachments) {
|
|
136
|
+
try {
|
|
137
|
+
const userContext = this.messengerState.userContext;
|
|
138
|
+
const isAuthenticated = userContext?.email && userContext?.name;
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
140
|
+
// If user is authenticated, silently identify them first
|
|
141
|
+
if (isAuthenticated) {
|
|
142
|
+
try {
|
|
143
|
+
await this.apiService.identifyContact({
|
|
144
|
+
name: userContext.name,
|
|
145
|
+
email: userContext.email,
|
|
146
|
+
});
|
|
147
|
+
console.log('[MessengerWidget] User auto-identified for conversation');
|
|
148
|
+
} catch (error) {
|
|
149
|
+
// If identification fails with a non-critical error, continue anyway
|
|
150
|
+
if (error?.code !== 'ALREADY_IDENTIFIED') {
|
|
151
|
+
console.warn('[MessengerWidget] Auto-identification failed:', error);
|
|
152
|
+
}
|
|
147
153
|
}
|
|
154
|
+
} else {
|
|
155
|
+
// Unauthenticated user - show pre-chat form
|
|
156
|
+
this.messengerState.pendingMessage = {
|
|
157
|
+
content: messageContent,
|
|
158
|
+
attachments: pendingAttachments,
|
|
159
|
+
};
|
|
160
|
+
this.messengerState.setView('prechat');
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
148
163
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
if (openConversation) {
|
|
154
|
-
this.messengerState.setActiveConversation(openConversation.id);
|
|
155
|
-
await this._handleSendMessage(
|
|
156
|
-
openConversation.id,
|
|
157
|
-
{ content: messageContent },
|
|
158
|
-
pendingAttachments
|
|
159
|
-
);
|
|
160
|
-
return openConversation;
|
|
161
|
-
}
|
|
164
|
+
// Check for existing open conversation
|
|
165
|
+
const openConversation = this.messengerState.conversations.find(
|
|
166
|
+
(c) => c.status === 'open'
|
|
167
|
+
);
|
|
162
168
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
if (openConversation) {
|
|
170
|
+
this.messengerState.setActiveConversation(openConversation.id);
|
|
171
|
+
await this._handleSendMessage(
|
|
172
|
+
openConversation.id,
|
|
173
|
+
{ content: messageContent },
|
|
166
174
|
pendingAttachments
|
|
167
175
|
);
|
|
168
|
-
|
|
169
|
-
console.error('[MessengerWidget] Failed to start conversation:', error);
|
|
170
|
-
return null;
|
|
176
|
+
return openConversation;
|
|
171
177
|
}
|
|
178
|
+
|
|
179
|
+
return await this.startNewConversation(
|
|
180
|
+
messageContent,
|
|
181
|
+
'',
|
|
182
|
+
pendingAttachments
|
|
183
|
+
);
|
|
184
|
+
} catch (error) {
|
|
185
|
+
console.error('[MessengerWidget] Failed to start conversation:', error);
|
|
186
|
+
return null;
|
|
172
187
|
}
|
|
188
|
+
}
|
|
173
189
|
|
|
174
190
|
async _handleSelectConversation(conversationId) {
|
|
175
191
|
try {
|
|
@@ -791,34 +807,19 @@ export class MessengerWidget extends BaseWidget {
|
|
|
791
807
|
};
|
|
792
808
|
}
|
|
793
809
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
if (userContext?.email && userContext?.name) {
|
|
797
|
-
try {
|
|
798
|
-
await this.apiService.identifyContact({
|
|
799
|
-
name: userContext.name,
|
|
800
|
-
email: userContext.email,
|
|
801
|
-
});
|
|
802
|
-
console.log('[MessengerWidget] User identified successfully');
|
|
803
|
-
} catch (error) {
|
|
804
|
-
if (error?.code !== 'ALREADY_IDENTIFIED') {
|
|
805
|
-
console.warn('[MessengerWidget] Identification failed:', error);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
}
|
|
810
|
+
async onMount() {
|
|
811
|
+
this.loadInitialData();
|
|
809
812
|
|
|
810
|
-
|
|
813
|
+
if (this.apiService?.sessionToken) {
|
|
814
|
+
this._initWebSocket();
|
|
815
|
+
}
|
|
811
816
|
|
|
812
|
-
|
|
813
|
-
this._initWebSocket();
|
|
814
|
-
}
|
|
817
|
+
this.checkAgentAvailability();
|
|
815
818
|
|
|
819
|
+
this._availabilityInterval = setInterval(() => {
|
|
816
820
|
this.checkAgentAvailability();
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
this.checkAgentAvailability();
|
|
820
|
-
}, 60000);
|
|
821
|
-
}
|
|
821
|
+
}, 60000);
|
|
822
|
+
}
|
|
822
823
|
|
|
823
824
|
onDestroy() {
|
|
824
825
|
if (this._stateUnsubscribe) {
|