@product7/product7-js 0.6.3 → 0.6.5

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.6.3",
3
+ "version": "0.6.5",
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",
@@ -399,7 +399,38 @@ export class LiveChatWidget extends BaseWidget {
399
399
  });
400
400
 
401
401
  if (response.status && response.data) {
402
- console.log('[LiveChatWidget] Message sent:', response.data.id);
402
+ // Reconcile the optimistic 'Sending…' message with the server's
403
+ // confirmation as soon as the POST returns. Don't depend on the WS
404
+ // echo alone — when the WebSocket frame is dropped (brief
405
+ // disconnect, slow network, server send-buffer full), the
406
+ // optimistic message stays stuck on 'Sending…' forever because
407
+ // upsertMessage's match window is finite.
408
+ const serverData = response.data;
409
+ let attachments = [];
410
+ if (serverData.attachments) {
411
+ try {
412
+ attachments =
413
+ typeof serverData.attachments === 'string'
414
+ ? JSON.parse(serverData.attachments)
415
+ : serverData.attachments;
416
+ } catch (e) {
417
+ attachments = [];
418
+ }
419
+ }
420
+ this.LiveChatState.upsertMessage(
421
+ conversationId,
422
+ {
423
+ id: serverData.id,
424
+ content: serverData.content,
425
+ isOwn: true,
426
+ timestamp: serverData.created_at,
427
+ attachments:
428
+ Array.isArray(attachments) && attachments.length > 0
429
+ ? attachments
430
+ : undefined,
431
+ },
432
+ { reconcileOwnOptimistic: true, optimisticMatchWindowMs: 60000 }
433
+ );
403
434
  }
404
435
 
405
436
  if (this.apiService?.mock) {
@@ -27,8 +27,10 @@
27
27
  }
28
28
 
29
29
  _updateContent() {
30
- const avatarsHtml = this.state.showAvatars ? this._renderAvatarStack() : '';
30
+ const isUnavailable = this.state.businessHoursState === 'offline' || this.state.businessHoursState === 'away';
31
+ const avatarsHtml = (this.state.showAvatars && !isUnavailable) ? this._renderAvatarStack() : '';
31
32
  const recentChangelogHtml = this._renderRecentChangelog();
33
+ const availabilityHtml = this._renderAvailabilityStatus();
32
34
 
33
35
  this.element.innerHTML = `
34
36
  <div class="liveChat-home-scroll">
@@ -37,7 +39,7 @@
37
39
  <div class="liveChat-home-logo">
38
40
  ${this.options.logoUrl ? `<img src="${this.options.logoUrl}" alt="${this.state.teamName}" />` : ''}
39
41
  </div>
40
- <div class="liveChat-home-avatars">${avatarsHtml}</div>
42
+ <div class="liveChat-home-avatars">${avatarsHtml || availabilityHtml}</div>
41
43
  </div>
42
44
  <div class="liveChat-home-welcome">
43
45
  <span class="liveChat-home-greeting">${this.state.greetingMessage}</span>
@@ -104,7 +106,7 @@
104
106
  return `
105
107
  <div class="liveChat-home-availability">
106
108
  <span class="liveChat-availability-dot liveChat-availability-away"></span>
107
- <span class="liveChat-availability-text">${this.state.responseTime}</span>
109
+ <span class="liveChat-availability-text">We're currently away</span>
108
110
  </div>
109
111
  `;
110
112
  }