@flowengage/react-chatbot 5.0.20 → 5.0.22

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.
@@ -3241,11 +3241,18 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3241
3241
  n && e && t.length > 0 && (console.log("[FlowEngageProvider] safety-net: syncing voice transcript on unmount"), n.beaconSyncVoice(e, t) || n.syncVoice(e, t).catch(() => {}), Et.current = !0);
3242
3242
  }
3243
3243
  }, [Fe, _]);
3244
- let Bt = p(null), Vt = A.current;
3244
+ let Bt = p(null);
3245
3245
  c(() => {
3246
- let e = A.current, t = k.current;
3247
- t && e && Bt.current !== C && (C ? t.updateChatStatus(e, "open").catch(() => {}) : Bt.current === !0 && t.updateChatStatus(e, "widget_closed").catch(() => {}), Bt.current = C);
3248
- }, [C, Vt]), c(() => {
3246
+ let e = k.current;
3247
+ !e || !y || Bt.current !== C && (C ? e.updateChatStatus(y, "open").catch(() => {}) : Bt.current === !0 && e.updateChatStatus(y, "widget_closed").catch(() => {}), Bt.current = C);
3248
+ }, [C, y]), c(() => {
3249
+ if (!C || !y) return;
3250
+ let e = setInterval(() => {
3251
+ let e = k.current;
3252
+ e && y && e.updateChatStatus(y, "widget_heartbeat").catch(() => {});
3253
+ }, 1e4);
3254
+ return () => clearInterval(e);
3255
+ }, [C, y]), c(() => {
3249
3256
  let e = () => {
3250
3257
  let e = A.current, t = k.current;
3251
3258
  !e || !t || typeof navigator > "u" || t.beaconWidgetClosed?.(e) || t.updateChatStatus(e, "widget_closed").catch(() => {});
@@ -3265,7 +3272,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3265
3272
  l,
3266
3273
  At
3267
3274
  ]);
3268
- let Ht = async () => {
3275
+ let Vt = async () => {
3269
3276
  if (!(!O?.callId || !k.current || !ot.current || !y)) {
3270
3277
  Mt(), gt.current = O.callId, Nt();
3271
3278
  try {
@@ -3355,7 +3362,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3355
3362
  rt("We couldn't connect the call right now. Please try again.");
3356
3363
  }
3357
3364
  }
3358
- }, Ut = async () => {
3365
+ }, Ht = async () => {
3359
3366
  if (!O?.callId || !k.current || !y) {
3360
3367
  Ft("reject_call_without_server_context");
3361
3368
  return;
@@ -3368,15 +3375,15 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3368
3375
  } finally {
3369
3376
  Ft("reject_call_finally");
3370
3377
  }
3371
- }, Wt = p(Ut);
3372
- Wt.current = Ut, c(() => {
3378
+ }, Ut = p(Ht);
3379
+ Ut.current = Ht, c(() => {
3373
3380
  if (!O?.callId || Je) {
3374
3381
  Nt();
3375
3382
  return;
3376
3383
  }
3377
3384
  let e = O.callId;
3378
3385
  return Nt(), j.current = window.setTimeout(() => {
3379
- lt.current?.callId === e && gt.current !== e && ht.current !== e && Wt.current();
3386
+ lt.current?.callId === e && gt.current !== e && ht.current !== e && Ut.current();
3380
3387
  }, oe), () => {
3381
3388
  j.current &&= (window.clearTimeout(j.current), null);
3382
3389
  };
@@ -3385,7 +3392,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3385
3392
  Nt,
3386
3393
  O?.callId
3387
3394
  ]);
3388
- let Gt = async () => {
3395
+ let Wt = async () => {
3389
3396
  if (!Je || !k.current || !y) {
3390
3397
  Ft("end_call_without_server_context");
3391
3398
  return;
@@ -3398,14 +3405,14 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3398
3405
  } finally {
3399
3406
  Ft("end_call_finally");
3400
3407
  }
3401
- }, Kt = () => {
3408
+ }, Gt = () => {
3402
3409
  let e = dt.current?.getAudioTracks?.() || [], t = ut.current?.getSenders?.().map((e) => e.track).filter((e) => e?.kind === "audio") || [], n = [...e, ...t].filter(Boolean);
3403
3410
  if (n.length === 0) return;
3404
3411
  let r = !et;
3405
3412
  n.forEach((e) => {
3406
3413
  e.enabled = !r;
3407
3414
  }), tt(r);
3408
- }, qt = async (e = {}) => {
3415
+ }, Kt = async (e = {}) => {
3409
3416
  let t = e.notifyChatInitiated === !0;
3410
3417
  if (w(!0), !(!t || !k.current || !y || typeof window > "u")) {
3411
3418
  try {
@@ -3418,7 +3425,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3418
3425
  await k.current.updateChatStatus(y, "open");
3419
3426
  } catch {}
3420
3427
  }
3421
- }, Jt = async (e) => {
3428
+ }, qt = async (e) => {
3422
3429
  let t = Pt(e);
3423
3430
  if (!t || !k.current || !A.current) return t;
3424
3431
  try {
@@ -3431,26 +3438,26 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3431
3438
  console.error("[FlowEngageProvider] failed to persist visitor email", e);
3432
3439
  }
3433
3440
  return t;
3434
- }, Yt = () => {
3441
+ }, Jt = () => {
3435
3442
  !y || !ot.current?.connected || vt.current || (vt.current = !0, ot.current.emit("typing:start", {
3436
3443
  chatId: y,
3437
3444
  sender: "user"
3438
3445
  }));
3439
- }, Xt = () => {
3446
+ }, Yt = () => {
3440
3447
  !y || !ot.current?.connected || !vt.current || (vt.current = !1, ot.current.emit("typing:stop", {
3441
3448
  chatId: y,
3442
3449
  sender: "user"
3443
3450
  }));
3444
- }, Zt = (e = "") => {
3451
+ }, Xt = (e = "") => {
3445
3452
  let t = typeof e == "string" ? e : "";
3446
3453
  !y || !ot.current?.connected || t !== "" && yt.current === t || (yt.current = t, ot.current.emit("typing:update", {
3447
3454
  chatId: y,
3448
3455
  sender: "user",
3449
3456
  text: t
3450
3457
  }));
3451
- }, Qt = async (e, t = "", n = null, a = {}) => {
3458
+ }, Zt = async (e, t = "", n = null, a = {}) => {
3452
3459
  if (!(typeof e == "string" && e.trim()) || !k.current || !y || l !== "ready" || He) return;
3453
- Xt();
3460
+ Yt();
3454
3461
  let o = `pending-user-${Date.now()}`, s = {
3455
3462
  id: o,
3456
3463
  sender: "user",
@@ -3509,10 +3516,10 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3509
3516
  je(!1), Ne("");
3510
3517
  }, ie)) : h(e);
3511
3518
  }
3512
- }, $t = async (e) => {
3519
+ }, Qt = async (e) => {
3513
3520
  if (!k.current || !e) throw Error("Upload is unavailable right now.");
3514
3521
  return k.current.uploadChatFile(e);
3515
- }, en = async (e) => {
3522
+ }, $t = async (e) => {
3516
3523
  if (!(!k.current || !y)) {
3517
3524
  try {
3518
3525
  let t = e ? "voice" : "text";
@@ -3520,7 +3527,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3520
3527
  } catch {}
3521
3528
  Ie(e), e && (Et.current = !1);
3522
3529
  }
3523
- }, tn = async (e) => {
3530
+ }, en = async (e) => {
3524
3531
  if (Et.current) return;
3525
3532
  if (Et.current = !0, !k.current || !y || !e?.length) {
3526
3533
  Ie(!1);
@@ -3549,9 +3556,9 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3549
3556
  } finally {
3550
3557
  Ie(!1);
3551
3558
  }
3552
- }, nn = async () => {
3559
+ }, tn = async () => {
3553
3560
  if (!(!k.current || !y)) {
3554
- Fe && !Et.current && Tt.current.length > 0 && await tn(Tt.current);
3561
+ Fe && !Et.current && Tt.current.length > 0 && await en(Tt.current);
3555
3562
  try {
3556
3563
  await k.current.endConversation(y);
3557
3564
  } catch {
@@ -3571,7 +3578,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3571
3578
  c(() => {
3572
3579
  if (Xe !== "connected" || !Je || !y || !Qe || !jt) return;
3573
3580
  let e = new Date(Qe).getTime(), t = Number.isFinite(e) ? Date.now() - e : 0, n = Math.max(0, jt * 1e3 - t), r = window.setTimeout(() => {
3574
- rt("The call ended because it reached the time limit."), Gt();
3581
+ rt("The call ended because it reached the time limit."), Wt();
3575
3582
  }, n);
3576
3583
  return () => window.clearTimeout(r);
3577
3584
  }, [
@@ -3579,7 +3586,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3579
3586
  Qe,
3580
3587
  Xe,
3581
3588
  y,
3582
- Gt,
3589
+ Wt,
3583
3590
  jt
3584
3591
  ]), c(() => {
3585
3592
  let e = () => {
@@ -3600,12 +3607,12 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3600
3607
  window.removeEventListener("pagehide", e), window.removeEventListener("beforeunload", e);
3601
3608
  };
3602
3609
  }, []);
3603
- let rn = o(() => {
3610
+ let nn = o(() => {
3604
3611
  let e = i?.siteId;
3605
3612
  ge(e), st.current = !0, ct.current = null, ot.current?.disconnect(), S([]), b(""), A.current = "", Ue(!1), re(!1), D(null), de(null), at(!0), s((e) => e + 1);
3606
- }, [i?.siteId]), an = o((e) => {
3613
+ }, [i?.siteId]), rn = o((e) => {
3607
3614
  i?.siteId, st.current = !1, ct.current = e, ot.current?.disconnect(), S([]), b(""), A.current = "", Ue(!1), re(!1), D(null), de(null), at(!0), s((e) => e + 1);
3608
- }, [i?.siteId]), on = f(() => ({
3615
+ }, [i?.siteId]), an = f(() => ({
3609
3616
  status: l,
3610
3617
  error: d,
3611
3618
  runtimeConfig: _,
@@ -3639,33 +3646,33 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3639
3646
  historyRef: Tt,
3640
3647
  hasSyncedRef: Et,
3641
3648
  dismissCallError: Mt,
3642
- captureVisitorEmail: Jt,
3643
- startTyping: Yt,
3644
- stopTyping: Xt,
3645
- updateTypingDraft: Zt,
3649
+ captureVisitorEmail: qt,
3650
+ startTyping: Jt,
3651
+ stopTyping: Yt,
3652
+ updateTypingDraft: Xt,
3646
3653
  notifyRouteChange: () => kt.current?.notifyRouteChange?.(),
3647
- openWidget: qt,
3654
+ openWidget: Kt,
3648
3655
  closeWidget: () => w(!1),
3649
3656
  toggleWidget: () => {
3650
3657
  if (C) {
3651
3658
  w(!1);
3652
3659
  return;
3653
3660
  }
3654
- qt({ notifyChatInitiated: !0 });
3661
+ Kt({ notifyChatInitiated: !0 });
3655
3662
  },
3656
- sendMessage: Qt,
3657
- uploadChatFile: $t,
3658
- setVoiceMode: en,
3659
- onMessageSync: tn,
3660
- endConversation: nn,
3661
- startNewChat: rn,
3662
- resumeChat: an,
3663
+ sendMessage: Zt,
3664
+ uploadChatFile: Qt,
3665
+ setVoiceMode: $t,
3666
+ onMessageSync: en,
3667
+ endConversation: tn,
3668
+ startNewChat: nn,
3669
+ resumeChat: rn,
3663
3670
  getVisitorChatHistory: () => k.current?.getVisitorChatHistory?.(),
3664
3671
  getVisitorChatThread: (e) => k.current?.getVisitorChatThread?.(e),
3665
- acceptCall: Ht,
3666
- rejectCall: Ut,
3667
- endWebRTCCall: Gt,
3668
- toggleCallMute: Kt
3672
+ acceptCall: Vt,
3673
+ rejectCall: Ht,
3674
+ endWebRTCCall: Wt,
3675
+ toggleCallMute: Gt
3669
3676
  }), [
3670
3677
  l,
3671
3678
  d,
@@ -3697,25 +3704,25 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3697
3704
  et,
3698
3705
  nt,
3699
3706
  r,
3707
+ qt,
3700
3708
  Jt,
3701
3709
  Yt,
3702
3710
  Xt,
3703
- Zt,
3711
+ Vt,
3704
3712
  Ht,
3705
- Ut,
3713
+ Wt,
3706
3714
  Gt,
3707
3715
  Kt,
3708
- qt,
3716
+ Zt,
3709
3717
  Qt,
3710
3718
  $t,
3711
3719
  en,
3712
3720
  tn,
3713
3721
  nn,
3714
- rn,
3715
3722
  Mt
3716
3723
  ]);
3717
3724
  return /* @__PURE__ */ g(In.Provider, {
3718
- value: on,
3725
+ value: an,
3719
3726
  children: n
3720
3727
  });
3721
3728
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowengage/react-chatbot",
3
- "version": "5.0.20",
3
+ "version": "5.0.22",
4
4
  "description": "Embeddable AI chat widget for React — powered by FlowEngage. Drop it in with a single siteId.",
5
5
  "keywords": [
6
6
  "chatbot",