@flowengage/react-chatbot 5.0.27 → 5.0.29

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,12 +3241,12 @@ 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(() => {}), Tt.current = !0);
3242
3242
  }
3243
3243
  }, [Pe, _]);
3244
- let zt = p(null);
3244
+ let zt = p(null), Bt = p(!1);
3245
3245
  c(() => {
3246
3246
  let e = k.current;
3247
- !e || !y || zt.current !== C && (C ? e.updateChatStatus(y, "open").catch(() => {}) : zt.current === !0 && e.updateChatStatus(y, "widget_closed").catch(() => {}), zt.current = C);
3247
+ !e || !y || zt.current !== C && (C && zt.current !== null ? (e.updateChatStatus(y, "open").catch(() => {}), Bt.current = !0) : zt.current === !0 && e.updateChatStatus(y, "widget_closed").catch(() => {}), zt.current = C);
3248
3248
  }, [C, y]), c(() => {
3249
- if (!C || !y) return;
3249
+ if (!C || !y || !Bt.current) return;
3250
3250
  let e = setInterval(() => {
3251
3251
  let e = k.current;
3252
3252
  e && y && e.updateChatStatus(y, "open").catch(() => {});
@@ -3272,7 +3272,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3272
3272
  l,
3273
3273
  kt
3274
3274
  ]);
3275
- let Bt = async () => {
3275
+ let Vt = async () => {
3276
3276
  if (!(!He?.callId || !k.current || !at.current || !y)) {
3277
3277
  jt(), ht.current = He.callId, Mt();
3278
3278
  try {
@@ -3362,7 +3362,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3362
3362
  nt("We couldn't connect the call right now. Please try again.");
3363
3363
  }
3364
3364
  }
3365
- }, Vt = async () => {
3365
+ }, Ht = async () => {
3366
3366
  if (!He?.callId || !k.current || !y) {
3367
3367
  Pt("reject_call_without_server_context");
3368
3368
  return;
@@ -3375,15 +3375,15 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3375
3375
  } finally {
3376
3376
  Pt("reject_call_finally");
3377
3377
  }
3378
- }, Ht = p(Vt);
3379
- Ht.current = Vt, c(() => {
3378
+ }, Ut = p(Ht);
3379
+ Ut.current = Ht, c(() => {
3380
3380
  if (!He?.callId || qe) {
3381
3381
  Mt();
3382
3382
  return;
3383
3383
  }
3384
3384
  let e = He.callId;
3385
3385
  return Mt(), gt.current = window.setTimeout(() => {
3386
- ct.current?.callId === e && ht.current !== e && mt.current !== e && Ht.current();
3386
+ ct.current?.callId === e && ht.current !== e && mt.current !== e && Ut.current();
3387
3387
  }, oe), () => {
3388
3388
  gt.current &&= (window.clearTimeout(gt.current), null);
3389
3389
  };
@@ -3392,7 +3392,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3392
3392
  Mt,
3393
3393
  He?.callId
3394
3394
  ]);
3395
- let Ut = async () => {
3395
+ let Wt = async () => {
3396
3396
  if (!qe || !k.current || !y) {
3397
3397
  Pt("end_call_without_server_context");
3398
3398
  return;
@@ -3405,16 +3405,16 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3405
3405
  } finally {
3406
3406
  Pt("end_call_finally");
3407
3407
  }
3408
- }, Wt = () => {
3408
+ }, Gt = () => {
3409
3409
  let e = ut.current?.getAudioTracks?.() || [], t = lt.current?.getSenders?.().map((e) => e.track).filter((e) => e?.kind === "audio") || [], n = [...e, ...t].filter(Boolean);
3410
3410
  if (n.length === 0) return;
3411
3411
  let r = !$e;
3412
3412
  n.forEach((e) => {
3413
3413
  e.enabled = !r;
3414
3414
  }), et(r);
3415
- }, Gt = async (e = {}) => {
3415
+ }, Kt = async (e = {}) => {
3416
3416
  let t = e.notifyChatInitiated === !0;
3417
- if (w(!0), !(!t || !k.current || !y || typeof window > "u")) {
3417
+ if (Bt.current = !0, w(!0), !(!t || !k.current || !y || typeof window > "u")) {
3418
3418
  try {
3419
3419
  await k.current.trackVisitor({
3420
3420
  chatId: y,
@@ -3425,7 +3425,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3425
3425
  await k.current.updateChatStatus(y, "open");
3426
3426
  } catch {}
3427
3427
  }
3428
- }, Kt = async (e) => {
3428
+ }, qt = async (e) => {
3429
3429
  let t = Nt(e);
3430
3430
  if (!t || !k.current || !ot.current) return t;
3431
3431
  try {
@@ -3438,26 +3438,26 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3438
3438
  console.error("[FlowEngageProvider] failed to persist visitor email", e);
3439
3439
  }
3440
3440
  return t;
3441
- }, qt = () => {
3441
+ }, Jt = () => {
3442
3442
  !y || !at.current?.connected || _t.current || (_t.current = !0, at.current.emit("typing:start", {
3443
3443
  chatId: y,
3444
3444
  sender: "user"
3445
3445
  }));
3446
- }, Jt = () => {
3446
+ }, Yt = () => {
3447
3447
  !y || !at.current?.connected || !_t.current || (_t.current = !1, at.current.emit("typing:stop", {
3448
3448
  chatId: y,
3449
3449
  sender: "user"
3450
3450
  }));
3451
- }, Yt = (e = "") => {
3451
+ }, Xt = (e = "") => {
3452
3452
  let t = typeof e == "string" ? e : "";
3453
3453
  !y || !at.current?.connected || t !== "" && vt.current === t || (vt.current = t, at.current.emit("typing:update", {
3454
3454
  chatId: y,
3455
3455
  sender: "user",
3456
3456
  text: t
3457
3457
  }));
3458
- }, Xt = async (e, t = "", n = null, a = {}) => {
3458
+ }, Zt = async (e, t = "", n = null, a = {}) => {
3459
3459
  if (!(typeof e == "string" && e.trim()) || !k.current || !y || l !== "ready" || Be) return;
3460
- Jt();
3460
+ Yt();
3461
3461
  let o = `pending-user-${Date.now()}`, s = {
3462
3462
  id: o,
3463
3463
  sender: "user",
@@ -3516,10 +3516,10 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3516
3516
  je(!1), O("");
3517
3517
  }, ie)) : h(e);
3518
3518
  }
3519
- }, Zt = async (e) => {
3519
+ }, Qt = async (e) => {
3520
3520
  if (!k.current || !e) throw Error("Upload is unavailable right now.");
3521
3521
  return k.current.uploadChatFile(e);
3522
- }, Qt = async (e) => {
3522
+ }, $t = async (e) => {
3523
3523
  if (!(!k.current || !y)) {
3524
3524
  try {
3525
3525
  let t = e ? "voice" : "text";
@@ -3527,7 +3527,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3527
3527
  } catch {}
3528
3528
  Fe(e), e && (Tt.current = !1);
3529
3529
  }
3530
- }, $t = async (e) => {
3530
+ }, en = async (e) => {
3531
3531
  if (Tt.current) return;
3532
3532
  if (Tt.current = !0, !k.current || !y || !e?.length) {
3533
3533
  Fe(!1);
@@ -3556,9 +3556,9 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3556
3556
  } finally {
3557
3557
  Fe(!1);
3558
3558
  }
3559
- }, en = async () => {
3559
+ }, tn = async () => {
3560
3560
  if (!(!k.current || !y)) {
3561
- Pe && !Tt.current && wt.current.length > 0 && await $t(wt.current);
3561
+ Pe && !Tt.current && wt.current.length > 0 && await en(wt.current);
3562
3562
  try {
3563
3563
  await k.current.endConversation(y);
3564
3564
  } catch {
@@ -3578,7 +3578,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3578
3578
  c(() => {
3579
3579
  if (Ye !== "connected" || !qe || !y || !Ze || !At) return;
3580
3580
  let e = new Date(Ze).getTime(), t = Number.isFinite(e) ? Date.now() - e : 0, n = Math.max(0, At * 1e3 - t), r = window.setTimeout(() => {
3581
- nt("The call ended because it reached the time limit."), Ut();
3581
+ nt("The call ended because it reached the time limit."), Wt();
3582
3582
  }, n);
3583
3583
  return () => window.clearTimeout(r);
3584
3584
  }, [
@@ -3586,7 +3586,7 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3586
3586
  Ze,
3587
3587
  Ye,
3588
3588
  y,
3589
- Ut,
3589
+ Wt,
3590
3590
  At
3591
3591
  ]), c(() => {
3592
3592
  let e = () => {
@@ -3603,12 +3603,12 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3603
3603
  window.removeEventListener("pagehide", e), window.removeEventListener("beforeunload", e);
3604
3604
  };
3605
3605
  }, []);
3606
- let tn = o(() => {
3606
+ let nn = o(() => {
3607
3607
  let e = i?.siteId;
3608
3608
  ge(e), A.current = !0, st.current = null, at.current?.disconnect(), S([]), b(""), ot.current = "", Ve(!1), re(!1), D(null), de(null), it(!0), s((e) => e + 1);
3609
- }, [i?.siteId]), nn = o((e) => {
3609
+ }, [i?.siteId]), rn = o((e) => {
3610
3610
  i?.siteId, A.current = !1, st.current = e, at.current?.disconnect(), S([]), b(""), ot.current = "", Ve(!1), re(!1), D(null), de(null), it(!0), s((e) => e + 1);
3611
- }, [i?.siteId]), rn = f(() => ({
3611
+ }, [i?.siteId]), an = f(() => ({
3612
3612
  status: l,
3613
3613
  error: d,
3614
3614
  runtimeConfig: _,
@@ -3642,33 +3642,33 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3642
3642
  historyRef: wt,
3643
3643
  hasSyncedRef: Tt,
3644
3644
  dismissCallError: jt,
3645
- captureVisitorEmail: Kt,
3646
- startTyping: qt,
3647
- stopTyping: Jt,
3648
- updateTypingDraft: Yt,
3645
+ captureVisitorEmail: qt,
3646
+ startTyping: Jt,
3647
+ stopTyping: Yt,
3648
+ updateTypingDraft: Xt,
3649
3649
  notifyRouteChange: () => Ot.current?.notifyRouteChange?.(),
3650
- openWidget: Gt,
3650
+ openWidget: Kt,
3651
3651
  closeWidget: () => w(!1),
3652
3652
  toggleWidget: () => {
3653
3653
  if (C) {
3654
3654
  w(!1);
3655
3655
  return;
3656
3656
  }
3657
- Gt({ notifyChatInitiated: !0 });
3657
+ Kt({ notifyChatInitiated: !0 });
3658
3658
  },
3659
- sendMessage: Xt,
3660
- uploadChatFile: Zt,
3661
- setVoiceMode: Qt,
3662
- onMessageSync: $t,
3663
- endConversation: en,
3664
- startNewChat: tn,
3665
- resumeChat: nn,
3659
+ sendMessage: Zt,
3660
+ uploadChatFile: Qt,
3661
+ setVoiceMode: $t,
3662
+ onMessageSync: en,
3663
+ endConversation: tn,
3664
+ startNewChat: nn,
3665
+ resumeChat: rn,
3666
3666
  getVisitorChatHistory: () => k.current?.getVisitorChatHistory?.(),
3667
3667
  getVisitorChatThread: (e) => k.current?.getVisitorChatThread?.(e),
3668
- acceptCall: Bt,
3669
- rejectCall: Vt,
3670
- endWebRTCCall: Ut,
3671
- toggleCallMute: Wt
3668
+ acceptCall: Vt,
3669
+ rejectCall: Ht,
3670
+ endWebRTCCall: Wt,
3671
+ toggleCallMute: Gt
3672
3672
  }), [
3673
3673
  l,
3674
3674
  d,
@@ -3700,25 +3700,25 @@ function Nr({ siteId: e, config: t, children: n, language: r = "en" }) {
3700
3700
  $e,
3701
3701
  tt,
3702
3702
  r,
3703
- Kt,
3704
3703
  qt,
3705
3704
  Jt,
3706
3705
  Yt,
3707
- Bt,
3706
+ Xt,
3708
3707
  Vt,
3709
- Ut,
3708
+ Ht,
3710
3709
  Wt,
3711
3710
  Gt,
3712
- Xt,
3711
+ Kt,
3713
3712
  Zt,
3714
3713
  Qt,
3715
3714
  $t,
3716
3715
  en,
3717
3716
  tn,
3717
+ nn,
3718
3718
  jt
3719
3719
  ]);
3720
3720
  return /* @__PURE__ */ g(In.Provider, {
3721
- value: rn,
3721
+ value: an,
3722
3722
  children: n
3723
3723
  });
3724
3724
  }
@@ -29965,11 +29965,11 @@ function kk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
29965
29965
  });
29966
29966
  }
29967
29967
  function Ak({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i, siteId: a, apiBaseUrl: s, chatId: l, historyRef: u, onMessageSync: d, voiceEndCounter: f }) {
29968
- let [h, v] = m("idle"), [y, b] = m(!1), [x, S] = m(!1), C = p(null), w = p(""), T = p(async () => {}), ee = p(!1), te = p(!1), ne = p(!1), re = p(!1), E = p("minimized"), ie = p(null), ae = p(null), oe = p(null), D = p(0), se = o((e = "minimized") => {
29968
+ let [h, v] = m("idle"), [y, b] = m(!1), [x, S] = m(!1), C = p(null), w = p(""), T = p(async () => {}), ee = p(!1), te = p(!1), ne = p(!1), re = p(!1), E = p("minimized"), ie = p(null), ae = p(null), oe = p(null), D = p(0), se = p(!1), ce = o((e = "minimized") => {
29969
29969
  E.current = e, re.current = !0, queueMicrotask(() => {
29970
29970
  ee.current || (ee.current = !0, T.current?.());
29971
29971
  });
29972
- }, [u]), ce = o(async (e) => {
29972
+ }, [u]), le = o(async (e) => {
29973
29973
  re.current = !0;
29974
29974
  try {
29975
29975
  await C.current?.endSession?.();
@@ -29999,10 +29999,10 @@ function Ak({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
29999
29999
  l,
30000
30000
  s
30001
30001
  ]);
30002
- return T.current = () => ce(E.current === "chat" ? t : n), c(() => {
30002
+ return T.current = () => le(E.current === "chat" ? t : n), c(() => {
30003
30003
  te.current = y;
30004
30004
  }, [y]), c(() => {
30005
- f && se("chat");
30005
+ f && ce("chat");
30006
30006
  }, [f]), c(() => {
30007
30007
  let e = !1, i = null;
30008
30008
  return (async () => {
@@ -30041,7 +30041,7 @@ function Ak({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30041
30041
  apiBaseUrl: s || null,
30042
30042
  getLastUserVoiceText: () => w.current,
30043
30043
  requestEndSession: () => {
30044
- se();
30044
+ se.current = !0;
30045
30045
  }
30046
30046
  })), n = a ? je(a) : null, o = !!n?.transcript, c = !!(a && Ve(a)), d = typeof window < "u" ? window.location.pathname : "/", f = typeof document < "u" ? document.title : "", p = d === "/" || d === "", m = null;
30047
30047
  try {
@@ -30073,11 +30073,17 @@ function Ak({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30073
30073
  },
30074
30074
  onUnhandledClientToolCall: (e) => console.error("[FlowEngage] Unhandled tool:", e?.tool_name),
30075
30075
  onModeChange: ({ mode: t }) => {
30076
- if (!e && (v(t === "speaking" ? "speaking" : "listening"), t === "listening" && S && !x)) {
30077
- x = !0;
30078
- try {
30079
- C.current?.sendUserMessage?.("continue with the tour");
30080
- } catch {}
30076
+ if (!e && (v(t === "speaking" ? "speaking" : "listening"), t === "listening")) {
30077
+ if (se.current) {
30078
+ se.current = !1, ce();
30079
+ return;
30080
+ }
30081
+ if (S && !x) {
30082
+ x = !0;
30083
+ try {
30084
+ C.current?.sendUserMessage?.("continue with the tour");
30085
+ } catch {}
30086
+ }
30081
30087
  }
30082
30088
  },
30083
30089
  onMessage: (t) => {
@@ -30093,13 +30099,13 @@ function Ak({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30093
30099
  e && Ae(a, e);
30094
30100
  } catch {}
30095
30101
  if (Ek(n, r)) {
30096
- se("minimized");
30102
+ ce("minimized");
30097
30103
  return;
30098
30104
  }
30099
30105
  if (te.current && n === "bot" && /are you still there|still there\??|hello\?|anyone there|checking in|you there|are you available|is anyone|did you step away/i.test(r)) if (D.current += 1, D.current === 2) try {
30100
30106
  C.current?.sendContextualUpdate?.("IMPORTANT: The visitor is muted and has not responded to your last 2 checks. Make exactly ONE more check. If there is still no response, say: 'I feel like you are not active, so I'm ending this session. You can connect with me anytime.' then immediately call the flowengage_end_session tool to end the voice session. Do NOT ask again after that.");
30101
30107
  } catch {}
30102
- else D.current >= 5 && se("minimized");
30108
+ else D.current >= 5 && ce("minimized");
30103
30109
  }
30104
30110
  },
30105
30111
  onError: (t) => {
@@ -30112,7 +30118,7 @@ function Ak({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30112
30118
  try {
30113
30119
  C.current?.setMicMuted?.(!0);
30114
30120
  } catch {}
30115
- b(!0), v("error"), se("chat");
30121
+ b(!0), v("error"), ce("chat");
30116
30122
  }
30117
30123
  },
30118
30124
  onDisconnect: (t) => {
@@ -30129,7 +30135,7 @@ function Ak({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30129
30135
  try {
30130
30136
  C.current?.setMicMuted?.(!0);
30131
30137
  } catch {}
30132
- b(!0), se("chat");
30138
+ b(!0), ce("chat");
30133
30139
  }
30134
30140
  });
30135
30141
  if (e) {
@@ -30173,7 +30179,7 @@ function Ak({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30173
30179
  r,
30174
30180
  a,
30175
30181
  s,
30176
- se
30182
+ ce
30177
30183
  ]), c(() => {
30178
30184
  if (!x) return;
30179
30185
  let e = (e) => {
@@ -30359,7 +30365,7 @@ function Ak({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30359
30365
  children: [
30360
30366
  /* @__PURE__ */ _("button", {
30361
30367
  onClick: () => {
30362
- S(!1), E.current = "chat", ce(t);
30368
+ S(!1), E.current = "chat", le(t);
30363
30369
  },
30364
30370
  style: {
30365
30371
  display: "flex",
@@ -30388,7 +30394,7 @@ function Ak({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30388
30394
  }),
30389
30395
  /* @__PURE__ */ _("button", {
30390
30396
  onClick: () => {
30391
- S(!1), E.current = "minimized", ce(n);
30397
+ S(!1), E.current = "minimized", le(n);
30392
30398
  },
30393
30399
  style: {
30394
30400
  display: "flex",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowengage/react-chatbot",
3
- "version": "5.0.27",
3
+ "version": "5.0.29",
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",