@axos-web-dev/shared-components 2.0.0-dev.29 → 2.0.0-dev.29-toasts

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.
Files changed (216) hide show
  1. package/dist/ATMLocator/ATMLocator.js +7 -2
  2. package/dist/Article/Article.css.d.ts +8 -4
  3. package/dist/ArticlesSet/ArticlesSet.css.d.ts +23 -1
  4. package/dist/ArticlesSet/ArticlesSet.css.js +7 -7
  5. package/dist/ArticlesSet/ArticlesSet.js +3 -4
  6. package/dist/Auth/ErrorAlert.js +8 -3
  7. package/dist/Auth/SignInPassword.js +1 -1
  8. package/dist/AwardsItem/AwardsItem.js +2 -2
  9. package/dist/Button/Button.js +26 -3
  10. package/dist/Calculators/ApyCalculatorUserTest/ApyCalculatorUserTest.css.d.ts +95 -0
  11. package/dist/Calculators/ApyCalculatorUserTest/ApyCalculatorUserTest.css.js +101 -0
  12. package/dist/Calculators/ApyCalculatorUserTest/index.d.ts +12 -0
  13. package/dist/Calculators/ApyCalculatorUserTest/index.js +618 -0
  14. package/dist/Calculators/AxosOneCalculator/BalanceAPYCalculator.css.js +2 -1
  15. package/dist/Calculators/Calculator.js +18 -3
  16. package/dist/Calculators/MarginTradingCalculator/index.js +7 -2
  17. package/dist/Calculators/index.d.ts +1 -0
  18. package/dist/Calculators/index.js +2 -0
  19. package/dist/Carousel/index.js +7 -2
  20. package/dist/Chatbot/AudioManager.d.ts +19 -0
  21. package/dist/Chatbot/AudioManager.js +61 -0
  22. package/dist/Chatbot/Bubble.css.js +2 -2
  23. package/dist/Chatbot/Bubble.js +1 -1
  24. package/dist/Chatbot/ChatWindow.css.d.ts +4 -0
  25. package/dist/Chatbot/ChatWindow.css.js +44 -36
  26. package/dist/Chatbot/ChatWindow.js +457 -387
  27. package/dist/Chatbot/Chatbot.css.js +0 -1
  28. package/dist/Chatbot/Chatbot.css.ts.vanilla.css.js +1 -0
  29. package/dist/Chatbot/Chatbot.d.ts +3 -0
  30. package/dist/Chatbot/Chatbot.js +103 -43
  31. package/dist/Chatbot/ChatbotMessage.js +183 -197
  32. package/dist/Chatbot/EllipsisAnimation.js +0 -6
  33. package/dist/Chatbot/ExpandChatToggle.d.ts +8 -0
  34. package/dist/Chatbot/ExpandChatToggle.js +74 -0
  35. package/dist/Chatbot/index.js +7 -2
  36. package/dist/Chatbot/store/chat.d.ts +8 -0
  37. package/dist/Chatbot/store/chat.js +14 -2
  38. package/dist/Chevron/Chevron.interface.d.ts +1 -0
  39. package/dist/Chevron/index.js +12 -3
  40. package/dist/Comparison/Comparison.css.d.ts +1 -0
  41. package/dist/Comparison/Comparison.css.js +16 -13
  42. package/dist/Comparison/Comparison.js +7 -2
  43. package/dist/Comparison/ComparisonSet.js +2 -1
  44. package/dist/Comparison/index.js +2 -1
  45. package/dist/ExecutiveBio/ExecutiveBio.css.d.ts +27 -0
  46. package/dist/ExecutiveBio/ExecutiveBio.js +281 -262
  47. package/dist/FaqAccordion/index.js +7 -2
  48. package/dist/FdicCallout/index.js +2 -1
  49. package/dist/FooterDisclosure/FooterDisclosure.js +1 -0
  50. package/dist/FooterSiteMap/AxosBank/FooterSiteMap.js +670 -659
  51. package/dist/Forms/ApplyNow.js +7 -2
  52. package/dist/Forms/CommercialDepositsACS.d.ts +3 -0
  53. package/dist/Forms/CommercialDepositsACS.js +278 -0
  54. package/dist/Forms/ContactUsBusiness.js +9 -4
  55. package/dist/Forms/ContactUsBusinessNameEmail.js +9 -4
  56. package/dist/Forms/ContactUsNMLSId.js +9 -4
  57. package/dist/Forms/ContactUsSchwabAAS.d.ts +11 -0
  58. package/dist/Forms/ContactUsSchwabAAS.js +263 -0
  59. package/dist/Forms/CpraRequest.js +8 -3
  60. package/dist/Forms/CraPublicFile.js +9 -4
  61. package/dist/Forms/EmailOnly.js +10 -5
  62. package/dist/Forms/Forms.css.d.ts +3 -0
  63. package/dist/Forms/MortgageRate/MortgageRateForm.js +7 -2
  64. package/dist/Forms/MortgageRate/MortgageRateWatch.js +7 -2
  65. package/dist/Forms/MortgageWarehouseLending.d.ts +1 -1
  66. package/dist/Forms/MortgageWarehouseLending.js +16 -11
  67. package/dist/Forms/SuccesForm.js +8 -3
  68. package/dist/Forms/index.d.ts +2 -0
  69. package/dist/Forms/index.js +4 -0
  70. package/dist/HeroBanner/HeroBanner.d.ts +1 -1
  71. package/dist/HeroBanner/HeroBanner.interface.d.ts +2 -0
  72. package/dist/HeroBanner/HeroBanner.js +33 -28
  73. package/dist/Hyperlink/index.js +9 -4
  74. package/dist/IconBillboard/IconBillboard.css.d.ts +16 -0
  75. package/dist/IconBillboard/IconBillboard.css.js +7 -4
  76. package/dist/IconBillboard/IconBillboard.interface.d.ts +2 -0
  77. package/dist/IconBillboard/IconBillboardSet.js +68 -62
  78. package/dist/IconBillboard/index.js +2 -1
  79. package/dist/IconBillboard/sections/CallToActionSection.js +3 -1
  80. package/dist/ImageBillboard/ImageBillboard.interface.d.ts +2 -0
  81. package/dist/ImageBillboard/ImageBillboardSet.d.ts +1 -1
  82. package/dist/ImageBillboard/ImageBillboardSet.js +28 -20
  83. package/dist/ImageLink/ImageLink.js +7 -2
  84. package/dist/ImageLink/ImageLinkSet.js +7 -2
  85. package/dist/ImageLink/index.js +8 -3
  86. package/dist/ImageToast/ImageToast.css.d.ts +5 -0
  87. package/dist/ImageToast/ImageToast.css.js +13 -0
  88. package/dist/ImageToast/index.d.ts +9 -0
  89. package/dist/{NavigationMenu/Navbar.js → ImageToast/index.js} +82 -93
  90. package/dist/Insight/Featured/CategorySelector.d.ts +1 -1
  91. package/dist/Insight/Featured/CategorySelector.js +10 -4
  92. package/dist/Insight/Featured/Featured.js +7 -2
  93. package/dist/Insight/Featured/Header.d.ts +1 -2
  94. package/dist/Insight/Featured/Header.js +7 -2
  95. package/dist/LandingPageHeader/LandingPageHeader.js +25 -16
  96. package/dist/Modal/Modal.js +8 -3
  97. package/dist/Modal/contextApi/store.d.ts +6 -1
  98. package/dist/Modal/contextApi/store.js +112 -6
  99. package/dist/NavigationMenu/AxosALTS/NavBar.module.js +23 -23
  100. package/dist/NavigationMenu/AxosALTS/index.js +42 -23
  101. package/dist/NavigationMenu/AxosAdvisor/NavBar.module.js +52 -52
  102. package/dist/NavigationMenu/AxosAdvisor/index.js +1 -1
  103. package/dist/NavigationMenu/AxosAdvisorServices/NavBar.module.js +53 -53
  104. package/dist/NavigationMenu/AxosAdvisorServices/index.js +31 -24
  105. package/dist/NavigationMenu/AxosBank/MobileMenu/MobileMenu.js +7 -2
  106. package/dist/NavigationMenu/AxosBank/MobileMenu/MobileNavData.d.ts +3 -9
  107. package/dist/NavigationMenu/AxosBank/MobileMenu/MobileNavData.js +13 -25
  108. package/dist/NavigationMenu/AxosBank/SubNavBar.js +37 -116
  109. package/dist/NavigationMenu/AxosBank/index.js +58 -39
  110. package/dist/NavigationMenu/AxosClearing/NavBar.module.js +37 -37
  111. package/dist/NavigationMenu/AxosClearing/SubNavBar.js +6 -6
  112. package/dist/NavigationMenu/AxosClearing/index.js +31 -16
  113. package/dist/NavigationMenu/AxosFiduciary/NavBar.module.js +40 -43
  114. package/dist/NavigationMenu/AxosFiduciary/index.js +5 -3
  115. package/dist/NavigationMenu/LaVictoire/index.js +8 -3
  116. package/dist/NavigationMenu/NavItem/index.js +141 -1
  117. package/dist/NavigationMenu/ServerNavigation/DropwdownButton.d.ts +7 -0
  118. package/dist/NavigationMenu/ServerNavigation/DropwdownButton.js +248 -0
  119. package/dist/NavigationMenu/ServerNavigation/Menu.d.ts +40 -0
  120. package/dist/NavigationMenu/ServerNavigation/Menu.js +268 -0
  121. package/dist/NavigationMenu/ServerNavigation/MobileMenu/MobileMenu.d.ts +13 -0
  122. package/dist/NavigationMenu/ServerNavigation/MobileMenu/MobileMenu.js +637 -0
  123. package/dist/NavigationMenu/ServerNavigation/MobileMenu/MobileMenu.module.js +86 -0
  124. package/dist/NavigationMenu/ServerNavigation/MobileMenu/MobileNavData.d.ts +51 -0
  125. package/dist/NavigationMenu/ServerNavigation/MobileMenu/MobileNavData.js +96 -0
  126. package/dist/NavigationMenu/ServerNavigation/MobileMenu/mobileReducer.d.ts +36 -0
  127. package/dist/NavigationMenu/ServerNavigation/MobileMenu/mobileReducer.js +105 -0
  128. package/dist/NavigationMenu/ServerNavigation/NavBar.module.js +125 -0
  129. package/dist/NavigationMenu/ServerNavigation/NavigationBar.css.d.ts +7 -0
  130. package/dist/NavigationMenu/ServerNavigation/NavigationBar.css.js +22 -0
  131. package/dist/NavigationMenu/ServerNavigation/SubNavBar.d.ts +6 -0
  132. package/dist/NavigationMenu/ServerNavigation/SubNavBar.js +281 -0
  133. package/dist/NavigationMenu/ServerNavigation/SubNavItem.d.ts +1 -0
  134. package/dist/NavigationMenu/ServerNavigation/SubNavItem.js +317 -0
  135. package/dist/NavigationMenu/ServerNavigation/SubNavbar.css.d.ts +60 -0
  136. package/dist/NavigationMenu/ServerNavigation/SubNavbar.css.js +22 -0
  137. package/dist/NavigationMenu/ServerNavigation/index.d.ts +7 -0
  138. package/dist/NavigationMenu/ServerNavigation/index.js +297 -0
  139. package/dist/NavigationMenu/index.d.ts +2 -0
  140. package/dist/NavigationMenu/index.js +19 -10
  141. package/dist/NavigationMenu/utils.d.ts +480 -0
  142. package/dist/NavigationMenu/utils.js +128 -0
  143. package/dist/PageNavSet/PageNavSet.js +16 -8
  144. package/dist/SecondaryFooter/index.js +8 -1
  145. package/dist/SetContainer/SetContainer.css.d.ts +3 -0
  146. package/dist/SetContainer/SetContainer.js +7 -2
  147. package/dist/SocialMediaBar/iconsRepository.js +8 -3
  148. package/dist/SocialMediaBar/index.js +1 -1
  149. package/dist/StepItemSet/StepItemSet.css.d.ts +3 -0
  150. package/dist/Table/Table.css.d.ts +14 -1
  151. package/dist/Table/Table.css.js +21 -19
  152. package/dist/Table/Table.d.ts +1 -1
  153. package/dist/Table/Table.js +5 -3
  154. package/dist/TopicalNavItem/TopicalNavItem.css.d.ts +0 -1
  155. package/dist/TopicalNavItem/TopicalNavItem.css.js +2 -4
  156. package/dist/TopicalNavItem/TopicalNavItem.js +11 -33
  157. package/dist/TopicalNavItem/index.js +1 -2
  158. package/dist/TopicalNavSet/TopicalNavSet.js +17 -9
  159. package/dist/VideoTile/VideoTile.js +7 -2
  160. package/dist/VideoWrapper/index.js +8 -3
  161. package/dist/assets/Article/Article.css +8 -4
  162. package/dist/assets/ArticlesSet/ArticlesSet.css +54 -39
  163. package/dist/assets/Auth/SignIn.css +2 -1
  164. package/dist/assets/Calculators/ApyCalculatorUserTest/ApyCalculatorUserTest.css +424 -0
  165. package/dist/assets/Calculators/AxosOneCalculator/BalanceAPYCalculator.css +2 -2
  166. package/dist/assets/CallToActionBar/CallToActionBar.css +2 -0
  167. package/dist/assets/Chatbot/AnimatedGradientBorder.css +1 -1
  168. package/dist/assets/Chatbot/Bubble.css +6 -2
  169. package/dist/assets/Chatbot/ChatWindow.css +120 -65
  170. package/dist/assets/Comparison/Comparison.css +32 -29
  171. package/dist/assets/DownloadTile/DownloadTile.css +0 -5
  172. package/dist/assets/ExecutiveBio/ExecutiveBio.css +55 -17
  173. package/dist/assets/FaqAccordion/FaqAccordion.css +1 -1
  174. package/dist/assets/FooterSiteMap/AxosBank/FooterSiteMap.css +2 -2
  175. package/dist/assets/Forms/Forms.css +3 -2
  176. package/dist/assets/HeroBanner/HeroBanner.css +1 -0
  177. package/dist/assets/IconBillboard/IconBillboard.css +64 -13
  178. package/dist/assets/ImageToast/ImageToast.css +39 -0
  179. package/dist/assets/Insight/Featured/Header.css +4 -2
  180. package/dist/assets/NavigationMenu/AxosALTS/NavBar.css +265 -264
  181. package/dist/assets/NavigationMenu/AxosAdvisor/NavBar.css +609 -609
  182. package/dist/assets/NavigationMenu/AxosAdvisorServices/NavBar.css +631 -630
  183. package/dist/assets/NavigationMenu/AxosClearing/NavBar.css +485 -484
  184. package/dist/assets/NavigationMenu/AxosFiduciary/NavBar.css +428 -427
  185. package/dist/assets/NavigationMenu/ServerNavigation/MobileMenu/MobileMenu.css +353 -0
  186. package/dist/assets/NavigationMenu/ServerNavigation/NavBar.css +483 -0
  187. package/dist/assets/NavigationMenu/ServerNavigation/NavigationBar.css +40 -0
  188. package/dist/assets/NavigationMenu/ServerNavigation/SubNavbar.css +87 -0
  189. package/dist/assets/SetContainer/SetContainer.css +7 -10
  190. package/dist/assets/SocialMediaBar/SocialMediaBar.css +1 -0
  191. package/dist/assets/StepItemSet/StepItemSet.css +3 -3
  192. package/dist/assets/Table/Table.css +82 -77
  193. package/dist/assets/TopicalNavItem/TopicalNavItem.css +25 -52
  194. package/dist/assets/TopicalNavSet/TopicalNavSet.css +28 -6
  195. package/dist/assets/VideoTile/VideoTile.css +3 -0
  196. package/dist/assets/globals.css +34 -2
  197. package/dist/globals.css.js +8 -1
  198. package/dist/icons/QuoteIconGrey.js +1 -0
  199. package/dist/icons/QuoteIconWhite.js +1 -0
  200. package/dist/icons/QuoteIconYellow.js +1 -0
  201. package/dist/index.css.js +8 -1
  202. package/dist/main.js +40 -17
  203. package/dist/utils/allowedAxosDomains.js +8 -13
  204. package/dist/utils/appendQueryParams.d.ts +3 -1
  205. package/dist/utils/appendQueryParams.js +66 -66
  206. package/dist/utils/index.js +3 -1
  207. package/dist/utils/tealiumOrganicFallback.d.ts +21 -0
  208. package/dist/utils/tealiumOrganicFallback.js +26 -0
  209. package/dist/utils/useVisibility.d.ts +1 -0
  210. package/dist/utils/useVisibility.js +21 -0
  211. package/dist/vite-env.d.js +1 -0
  212. package/package.json +148 -148
  213. package/dist/NavigationMenu/Navbar.d.ts +0 -5
  214. package/dist/NavigationMenu/SignInNavButton.d.ts +0 -1
  215. package/dist/NavigationMenu/SignInNavButton.js +0 -363
  216. package/dist/assets/Chatbot/Chatbot.css +0 -3
@@ -1,4 +1,3 @@
1
- import '../assets/Chatbot/Chatbot.css';/* empty css */
2
1
  var chatbotAXB = "_1hpv6vm0";
3
2
  var chatbotUFB = "_1hpv6vm1";
4
3
  export {
@@ -1,3 +1,6 @@
1
+ import { default as AudioManager } from './AudioManager';
2
+
3
+ export declare const audioManager: AudioManager;
1
4
  export type ChatbotProps = {
2
5
  project?: "axos" | "ufb";
3
6
  debug?: boolean;
@@ -1,22 +1,20 @@
1
1
  "use client";
2
2
  import { jsxs, jsx } from "react/jsx-runtime";
3
+ import { usePageVisibility } from "../utils/useVisibility.js";
3
4
  import { useRef, useState, useEffect } from "react";
4
- import { useLocation, useMount, useUnmount } from "react-use";
5
+ import { useMount, useUnmount } from "react-use";
5
6
  import notificationSound from "../assets/notification.mp3.js";
7
+ import AudioManager from "./AudioManager.js";
6
8
  import { Bubble } from "./Bubble.js";
7
9
  import { chatbotAXB, chatbotUFB } from "./Chatbot.css.js";
8
10
  import { ChatWindow } from "./ChatWindow.js";
9
11
  import { useOpenChat } from "./store/chat.js";
10
12
  import { useMessages } from "./store/messages.js";
11
- if (typeof window !== "undefined") {
12
- const OriginalAudio = window.Audio;
13
- class PatchedAudio extends OriginalAudio {
14
- constructor(src) {
15
- const newSrc = src === "https://websdk.ujet.co/v3/ping.mp3" ? notificationSound : src;
16
- super(newSrc);
17
- }
18
- }
19
- window.Audio = PatchedAudio;
13
+ const audioManager = new AudioManager();
14
+ audioManager.installUjetAudioOverride(notificationSound);
15
+ audioManager.setSoundEnabled(false);
16
+ function isChat(obj) {
17
+ return obj !== null && typeof obj === "object" && "id" in obj && "agent" in obj && typeof obj.connect === "function";
20
18
  }
21
19
  const Chatbot = ({
22
20
  project = "axos",
@@ -25,6 +23,7 @@ const Chatbot = ({
25
23
  config
26
24
  }) => {
27
25
  const {
26
+ isOpen,
28
27
  hasOpenedOnce,
29
28
  toggle,
30
29
  reset,
@@ -32,9 +31,15 @@ const Chatbot = ({
32
31
  hasEscalated,
33
32
  endEscalation,
34
33
  unblockInput,
35
- blockInput
34
+ blockInput,
35
+ hasStarted,
36
+ setChatStarted,
37
+ resetChatStarted,
38
+ setChatStatus,
39
+ displayThankyouMessage,
40
+ hideDisplayThankyouMessage
36
41
  } = useOpenChat();
37
- const location = useLocation();
42
+ const isVisible = usePageVisibility();
38
43
  const { addMessage, addMessages, clearMessages, messages } = useMessages();
39
44
  const clientRef = useRef(null);
40
45
  const menuRef = useRef(null);
@@ -43,7 +48,6 @@ const Chatbot = ({
43
48
  const chatLoading = useRef(false);
44
49
  const agent_virtual = useRef(null);
45
50
  const [status, setStatus] = useState("idle");
46
- const [hasStarted, setHasStarted] = useState(false);
47
51
  const [menusLoaded, setMenusLoaded] = useState(false);
48
52
  const [isTyping, setIsTyping] = useState(false);
49
53
  const [scalationStarted, setScalationStarted] = useState(false);
@@ -73,7 +77,7 @@ const Chatbot = ({
73
77
  $index: -10,
74
78
  $userId: 0
75
79
  };
76
- const custom_data = {
80
+ const custom_data = () => ({
77
81
  unsigned: {
78
82
  facingBrandId: {
79
83
  label: "facingBrandId",
@@ -93,10 +97,10 @@ const Chatbot = ({
93
97
  },
94
98
  url: {
95
99
  label: "url",
96
- value: location.href
100
+ value: window.location.href
97
101
  }
98
102
  }
99
- };
103
+ });
100
104
  const onReadyHandler = async () => {
101
105
  console.log("Chat client is ready");
102
106
  if (clientRef.current) {
@@ -264,12 +268,20 @@ const Chatbot = ({
264
268
  };
265
269
  const startChat = async (source) => {
266
270
  const client = clientRef.current;
267
- if (!client) return;
268
- if (hasStarted) return;
271
+ if (!client) {
272
+ console.log(`no client detected`);
273
+ return;
274
+ }
275
+ if (hasStarted) {
276
+ console.log(`has started is ${hasStarted}`);
277
+ return;
278
+ }
279
+ hideDisplayThankyouMessage();
269
280
  if (chatLoading.current) {
270
281
  console.log(`startChat skipped [${source}] — already in progress`);
271
282
  return;
272
283
  }
284
+ setChatStatus("connected");
273
285
  try {
274
286
  console.log(`Starting chat [${source}]`, chatRef.current);
275
287
  chatLoading.current = true;
@@ -304,8 +316,10 @@ const Chatbot = ({
304
316
  if (!foundMenu) {
305
317
  throw new Error("Menu not found: " + menuOption);
306
318
  }
307
- const newChat = await client.createChat(menuId, { custom_data });
308
- if (newChat !== null) {
319
+ const newChat = await client.createChat(menuId, {
320
+ custom_data: custom_data()
321
+ });
322
+ if (newChat && typeof newChat === "object" && isChat(newChat)) {
309
323
  chatRef.current = newChat;
310
324
  agent_virtual.current = newChat.agent;
311
325
  console.log("Chat created id:", newChat.id);
@@ -314,25 +328,16 @@ const Chatbot = ({
314
328
  console.error("Error creating chat:", err);
315
329
  } finally {
316
330
  chatLoading.current = false;
317
- setHasStarted(true);
318
- if (clientRef?.current?.chat?.state?.status == "va_assigned") {
319
- const OriginalAudio = window.Audio;
320
- class PatchedAudio extends OriginalAudio {
321
- constructor(src) {
322
- const newSrc = src === "https://websdk.ujet.co/v3/ping.mp3" ? notificationSound : src;
323
- super(newSrc);
324
- }
325
- }
326
- window.Audio = PatchedAudio;
327
- }
331
+ setChatStarted();
328
332
  }
329
333
  };
330
334
  const handleClick = async () => {
335
+ audioManager.setSoundEnabled(true);
331
336
  toggle();
332
337
  if (hasStarted) return;
333
338
  if (!hasOpenedOnce) {
334
339
  await startChat("bubbleClick");
335
- setHasStarted(true);
340
+ setChatStarted();
336
341
  }
337
342
  };
338
343
  const onSendMessage = async (msg) => {
@@ -357,15 +362,26 @@ const Chatbot = ({
357
362
  }
358
363
  };
359
364
  const onEndChat = async () => {
360
- console.log("Ending chat");
365
+ console.log(`Ending chat [end chat]`);
361
366
  if (chatRef.current) {
362
- await clientRef.current?.finishChat();
363
- await chatRef.current?.destroy();
364
- clearMessages();
365
- chatRef.current = null;
366
- console.log("Chat ended");
367
- setHasStarted(false);
368
- endEscalation?.();
367
+ try {
368
+ await clientRef.current?.finishChat();
369
+ console.log(`Chat finished`);
370
+ try {
371
+ await chatRef.current?.destroy();
372
+ console.log(`Chat destroyed`);
373
+ clearMessages();
374
+ chatRef.current = null;
375
+ resetChatStarted();
376
+ console.log("Chat ended");
377
+ endEscalation?.();
378
+ } finally {
379
+ setChatStatus("ending");
380
+ displayThankyouMessage();
381
+ }
382
+ } catch (error) {
383
+ console.log(error, "from onEndChat");
384
+ }
369
385
  }
370
386
  };
371
387
  const onEndAndStartNewChat = async () => {
@@ -384,7 +400,7 @@ const Chatbot = ({
384
400
  deregisterEventHandlers();
385
401
  chatLoading.current = false;
386
402
  reset();
387
- setHasStarted(false);
403
+ resetChatStarted();
388
404
  setStatus("idle");
389
405
  clearMessages();
390
406
  endEscalation?.();
@@ -400,7 +416,7 @@ const Chatbot = ({
400
416
  };
401
417
  const onCloseAfterThankYou = async () => {
402
418
  reset();
403
- setHasStarted(false);
419
+ resetChatStarted();
404
420
  newChatSession();
405
421
  };
406
422
  const onPreviewTyping = async (msg) => {
@@ -414,6 +430,49 @@ const Chatbot = ({
414
430
  console.error("Error sending preview message:", error);
415
431
  }
416
432
  };
433
+ useEffect(() => {
434
+ if (chatRef.current) {
435
+ if (isVisible && isOpen) {
436
+ audioManager.setSoundEnabled(false);
437
+ }
438
+ if (isVisible && !isOpen) {
439
+ audioManager.setSoundEnabled(true);
440
+ }
441
+ if (!isVisible) {
442
+ audioManager.setSoundEnabled(true);
443
+ }
444
+ }
445
+ }, [isOpen, isVisible]);
446
+ useMount(() => {
447
+ const hasParams = () => {
448
+ return window.location.search.includes("utm_");
449
+ };
450
+ const tryStart = () => {
451
+ if (hasParams()) {
452
+ startChat("utm-ready");
453
+ return true;
454
+ }
455
+ return false;
456
+ };
457
+ if (tryStart()) return;
458
+ const original = history.replaceState;
459
+ history.replaceState = function(...args) {
460
+ original.apply(this, args);
461
+ if (tryStart()) {
462
+ history.replaceState = original;
463
+ }
464
+ };
465
+ const interval = setInterval(() => {
466
+ if (tryStart()) {
467
+ clearInterval(interval);
468
+ history.replaceState = original;
469
+ }
470
+ }, 100);
471
+ return () => {
472
+ clearInterval(interval);
473
+ history.replaceState = original;
474
+ };
475
+ });
417
476
  return menusLoaded && /* @__PURE__ */ jsxs(
418
477
  "div",
419
478
  {
@@ -440,5 +499,6 @@ const Chatbot = ({
440
499
  );
441
500
  };
442
501
  export {
443
- Chatbot
502
+ Chatbot,
503
+ audioManager
444
504
  };
@@ -19,31 +19,6 @@ function timeAgo(date) {
19
19
  minute: "2-digit"
20
20
  });
21
21
  }
22
- function convertBulletsToTable(text) {
23
- const lines = text.split("\n");
24
- const header = lines[0];
25
- const bulletLines = lines.filter((line) => line.trim().startsWith("•"));
26
- if (bulletLines.length === 0) return text;
27
- const fields = bulletLines.map((line) => {
28
- const [field] = line.split(":");
29
- const cleanField = field.replace(/•\s*\*\*|\*\*/g, "").trim();
30
- return cleanField;
31
- });
32
- const values = bulletLines.map((line) => {
33
- const [, value] = line.split(":");
34
- return value.trim();
35
- });
36
- const headerRow = `| ${fields.join(" | ")} |`;
37
- const separatorRow = `| ${fields.map(() => "-------").join(" | ")} |`;
38
- const valueRow = `| ${values.join(" | ")} |`;
39
- return `
40
- ### ${header}
41
-
42
- ${headerRow}
43
- ${separatorRow}
44
- ${valueRow}
45
- `;
46
- }
47
22
  const ChatbotMessage = ({
48
23
  msg,
49
24
  showAvatar,
@@ -93,186 +68,197 @@ const ChatbotMessage = ({
93
68
  }
94
69
  );
95
70
  }
96
- const checkInformationMortgage = typeof msg.content == "string" ? convertBulletsToTable(msg.content) : "";
97
- return /* @__PURE__ */ jsxs(Fragment, { children: [
98
- msg.type == "noti" && msg.$userType == "system" && msg.event == "escalationStarted" && /* @__PURE__ */ jsx("div", { className: notificationStyle, children: "We are connecting you with a human agent..." }, msg.$index),
99
- msg.type == "noti" && msg.$userType == "system" && msg.event == "memberLeft" && /* @__PURE__ */ jsxs("div", { className: notificationStyle, children: [
100
- /* @__PURE__ */ jsx("strong", { children: "Virtual Agent" }),
101
- " just left the conversation."
102
- ] }, msg.$index),
103
- msg.type == "noti" && msg.$userType == "system" && msg.event == "escalationAccepted" && /* @__PURE__ */ jsxs("div", { className: notificationStyle, children: [
104
- "You are now connected with a",
105
- " ",
106
- msg.to_agent ? /* @__PURE__ */ jsx("strong", { children: msg?.to_agent?.name }) : "an agent"
107
- ] }, msg.$index),
108
- msg.type == "noti" && msg.$userType == "virtual_agent" && msg.event == "escalationDeflected" && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
109
- "div",
110
- {
111
- className: notificationStyle,
112
- style: { fontSize: 12 },
113
- children: [
114
- "Our chat team is available weekdays, 8am-5pm, except federal bank holidays. For immediate assistance you can reach out to us at",
115
- " ",
116
- /* @__PURE__ */ jsx("a", { href: "tel:1-888-502-2967", children: "1-888-502-2967" }),
117
- "."
118
- ]
71
+ const checkInformationMortgage = typeof msg.content == "string" ? msg.content.replace(/•/g, "-").replace(/\\n/g, "\n") : "";
72
+ return /* @__PURE__ */ jsxs(
73
+ "div",
74
+ {
75
+ style: {
76
+ display: "flex",
77
+ flexDirection: "column"
119
78
  },
120
- msg.$index
121
- ) }),
122
- ["text", "markdown_template", "markdown"].includes(msg.type) && /* @__PURE__ */ jsx(
123
- "div",
124
- {
125
- className: clsx(
126
- messageStyle,
127
- msg.$userType == "end_user" ? user_msg : agent_msg
79
+ children: [
80
+ msg.type == "noti" && msg.$userType == "system" && msg.event == "escalationStarted" && /* @__PURE__ */ jsx("div", { className: notificationStyle, children: "We are connecting you with a human agent..." }, msg.$index),
81
+ msg.type == "noti" && msg.$userType == "system" && msg.event == "memberLeft" && /* @__PURE__ */ jsxs("div", { className: notificationStyle, children: [
82
+ /* @__PURE__ */ jsx("strong", { children: "Virtual Agent" }),
83
+ " just left the conversation."
84
+ ] }, msg.$index),
85
+ msg.type == "noti" && msg.$userType == "system" && msg.event == "escalationAccepted" && /* @__PURE__ */ jsxs("div", { className: notificationStyle, children: [
86
+ "You are now connected with a",
87
+ " ",
88
+ msg.to_agent ? /* @__PURE__ */ jsx("strong", { children: msg?.to_agent?.name }) : "an agent"
89
+ ] }, msg.$index),
90
+ msg.type == "noti" && msg.$userType == "virtual_agent" && msg.event == "escalationDeflected" && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
91
+ "div",
92
+ {
93
+ className: notificationStyle,
94
+ style: { fontSize: 12 },
95
+ children: [
96
+ "Our chat team is available weekdays, 8am-5pm, except federal bank holidays. For immediate assistance you can reach out to us at",
97
+ " ",
98
+ /* @__PURE__ */ jsx("a", { href: "tel:1-888-502-2967", children: "1-888-502-2967" }),
99
+ "."
100
+ ]
101
+ },
102
+ msg.$index
103
+ ) }),
104
+ ["text", "markdown_template", "markdown"].includes(msg.type) && /* @__PURE__ */ jsx(
105
+ "div",
106
+ {
107
+ className: clsx(
108
+ messageStyle,
109
+ msg.$userType == "end_user" ? user_msg : agent_msg
110
+ ),
111
+ children: /* @__PURE__ */ jsxs(
112
+ "div",
113
+ {
114
+ style: {
115
+ fontSize: 14,
116
+ display: "flex",
117
+ flexDirection: "column",
118
+ gap: 4
119
+ },
120
+ children: [
121
+ msg.$userType == "virtual_agent" && /* @__PURE__ */ jsxs(
122
+ "div",
123
+ {
124
+ style: {
125
+ display: "flex",
126
+ alignItems: "center",
127
+ gap: "8px"
128
+ },
129
+ children: [
130
+ showAvatar && /* @__PURE__ */ jsx(
131
+ "img",
132
+ {
133
+ width: 24,
134
+ height: 24,
135
+ src: virtualAgent?.avatar_url,
136
+ alt: "agent avatar"
137
+ }
138
+ ),
139
+ showName && /* @__PURE__ */ jsx("strong", { children: virtualAgent?.name })
140
+ ]
141
+ }
142
+ ),
143
+ msg.$userType != "end_user" ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
144
+ ReactMarkdown,
145
+ {
146
+ remarkPlugins: [[remarkGfm, { singleTilde: false }]],
147
+ components: {
148
+ p: ({ ...props }) => /* @__PURE__ */ jsx(
149
+ "p",
150
+ {
151
+ style: { margin: 0, fontSize: "inherit" },
152
+ title: new Date(msg.$timestamp).toLocaleTimeString([], {
153
+ hour: "2-digit",
154
+ minute: "2-digit"
155
+ }),
156
+ ...props
157
+ }
158
+ ),
159
+ a: ({ ...props }) => /* @__PURE__ */ jsx("a", { style: { wordBreak: "break-word" }, ...props }),
160
+ table: ({ node, ...props }) => /* @__PURE__ */ jsx("div", { style: { overflowX: "auto", marginTop: 4 }, children: /* @__PURE__ */ jsx(
161
+ "table",
162
+ {
163
+ ...props,
164
+ className: clsx(tableMsg),
165
+ style: { tableLayout: "fixed" }
166
+ }
167
+ ) }),
168
+ th: ({ node, ...props }) => /* @__PURE__ */ jsx("th", { ...props, className: clsx(tableHead) }),
169
+ td: ({ node, ...props }) => /* @__PURE__ */ jsx("td", { ...props, className: clsx(tableCell) }),
170
+ tr: ({ node, ...props }) => {
171
+ return /* @__PURE__ */ jsx("tr", { className: clsx(trMortgageTable), ...props });
172
+ }
173
+ },
174
+ children: msg?.content?.includes("Does this information look correct?") ? checkInformationMortgage : msg.content
175
+ }
176
+ ) }) : /* @__PURE__ */ jsx(
177
+ "div",
178
+ {
179
+ title: new Date(msg.$timestamp).toLocaleTimeString([], {
180
+ hour: "2-digit",
181
+ minute: "2-digit"
182
+ }),
183
+ children: msg.content
184
+ }
185
+ )
186
+ ]
187
+ }
188
+ )
189
+ },
190
+ msg.$index
128
191
  ),
129
- children: /* @__PURE__ */ jsxs(
192
+ msg.type == "inline_button" && Array.isArray(msg.buttons) && msg.buttons.length > 0 && /* @__PURE__ */ jsx("div", { className: inline_button_wrapper, children: msg.buttons.length !== 0 && Array.isArray(msg.buttons) && msg.buttons.map((button, index) => {
193
+ return /* @__PURE__ */ jsx(
194
+ "button",
195
+ {
196
+ className: inline_button,
197
+ onClick: () => {
198
+ onSend?.(button?.title);
199
+ },
200
+ children: button.title
201
+ },
202
+ index
203
+ );
204
+ }) }),
205
+ " ",
206
+ msg.event == "chatEnded" && msg.status == "failed" && /* @__PURE__ */ jsxs(Fragment, { children: [
207
+ /* @__PURE__ */ jsxs(
208
+ "div",
209
+ {
210
+ title: (/* @__PURE__ */ new Date()).toLocaleString(),
211
+ style: {
212
+ fontSize: 12,
213
+ color: "#888",
214
+ marginBottom: 4,
215
+ textAlign: "center"
216
+ },
217
+ children: [
218
+ "No team members are online at the moment.",
219
+ /* @__PURE__ */ jsx("br", {}),
220
+ " Please try again later."
221
+ ]
222
+ }
223
+ ),
224
+ /* @__PURE__ */ jsx("div", { style: { textAlign: "center", marginBottom: 12 }, children: /* @__PURE__ */ jsx("button", { className: endChatButtonStyle, onClick: onEndChat, children: "End Chat" }) })
225
+ ] }),
226
+ msg.event == "chatEnded" && msg.status != "failed" && /* @__PURE__ */ jsxs(Fragment, { children: [
227
+ /* @__PURE__ */ jsxs(
228
+ "div",
229
+ {
230
+ title: (/* @__PURE__ */ new Date()).toLocaleString(),
231
+ style: {
232
+ fontSize: 12,
233
+ color: "#888",
234
+ marginBottom: 4,
235
+ textAlign: "center"
236
+ },
237
+ children: [
238
+ "Thank you for chatting!",
239
+ /* @__PURE__ */ jsx("br", {}),
240
+ " This conversation has ended."
241
+ ]
242
+ }
243
+ ),
244
+ /* @__PURE__ */ jsx("div", { style: { textAlign: "center", marginBottom: 12 }, children: /* @__PURE__ */ jsx("button", { className: endChatButtonStyle, onClick: onEndChat, children: "End Chat" }) })
245
+ ] }),
246
+ msg.type == "text" && /* @__PURE__ */ jsx(
130
247
  "div",
131
248
  {
132
249
  style: {
133
- fontSize: 14,
134
- display: "flex",
135
- flexDirection: "column",
136
- gap: 4
250
+ textAlign: msg.$userType === "end_user" ? "right" : "left",
251
+ fontSize: 12,
252
+ color: vars.chatbot.window.timestampColor,
253
+ textTransform: "capitalize",
254
+ fontFamily: "inherit"
137
255
  },
138
- children: [
139
- msg.$userType == "virtual_agent" && /* @__PURE__ */ jsxs(
140
- "div",
141
- {
142
- style: {
143
- display: "flex",
144
- alignItems: "center",
145
- gap: "8px"
146
- },
147
- children: [
148
- showAvatar && /* @__PURE__ */ jsx(
149
- "img",
150
- {
151
- width: 24,
152
- height: 24,
153
- src: virtualAgent?.avatar_url,
154
- alt: "agent avatar"
155
- }
156
- ),
157
- showName && /* @__PURE__ */ jsx("strong", { children: virtualAgent?.name })
158
- ]
159
- }
160
- ),
161
- msg.$userType != "end_user" ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
162
- ReactMarkdown,
163
- {
164
- remarkPlugins: [[remarkGfm, { singleTilde: false }]],
165
- components: {
166
- p: ({ ...props }) => /* @__PURE__ */ jsx(
167
- "p",
168
- {
169
- style: { margin: 0, fontSize: "inherit" },
170
- title: new Date(msg.$timestamp).toLocaleTimeString([], {
171
- hour: "2-digit",
172
- minute: "2-digit"
173
- }),
174
- ...props
175
- }
176
- ),
177
- a: ({ ...props }) => /* @__PURE__ */ jsx("a", { style: { wordBreak: "break-word" }, ...props }),
178
- table: ({ node, ...props }) => /* @__PURE__ */ jsx("div", { style: { overflowX: "auto", marginTop: 4 }, children: /* @__PURE__ */ jsx(
179
- "table",
180
- {
181
- ...props,
182
- className: clsx(tableMsg),
183
- style: { tableLayout: "fixed" }
184
- }
185
- ) }),
186
- th: ({ node, ...props }) => /* @__PURE__ */ jsx("th", { ...props, className: clsx(tableHead) }),
187
- td: ({ node, ...props }) => /* @__PURE__ */ jsx("td", { ...props, className: clsx(tableCell) }),
188
- tr: ({ node, ...props }) => {
189
- return /* @__PURE__ */ jsx("tr", { className: clsx(trMortgageTable), ...props });
190
- }
191
- },
192
- children: msg?.content?.includes("Does this information look correct?") ? checkInformationMortgage : msg.content
193
- }
194
- ) }) : /* @__PURE__ */ jsx(
195
- "div",
196
- {
197
- title: new Date(msg.$timestamp).toLocaleTimeString([], {
198
- hour: "2-digit",
199
- minute: "2-digit"
200
- }),
201
- children: msg.content
202
- }
203
- )
204
- ]
256
+ children: timeText
205
257
  }
206
258
  )
207
- },
208
- msg.$index
209
- ),
210
- msg.type == "inline_button" && Array.isArray(msg.buttons) && msg.buttons.length > 0 && /* @__PURE__ */ jsx("div", { className: inline_button_wrapper, children: msg.buttons.length !== 0 && Array.isArray(msg.buttons) && msg.buttons.map((button, index) => {
211
- return /* @__PURE__ */ jsx(
212
- "button",
213
- {
214
- className: inline_button,
215
- onClick: () => {
216
- onSend?.(button?.title);
217
- },
218
- children: button.title
219
- },
220
- index
221
- );
222
- }) }),
223
- " ",
224
- msg.event == "chatEnded" && msg.status == "failed" && /* @__PURE__ */ jsxs(Fragment, { children: [
225
- /* @__PURE__ */ jsxs(
226
- "div",
227
- {
228
- title: (/* @__PURE__ */ new Date()).toLocaleString(),
229
- style: {
230
- fontSize: 12,
231
- color: "#888",
232
- marginBottom: 4,
233
- textAlign: "center"
234
- },
235
- children: [
236
- "No team members are online at the moment.",
237
- /* @__PURE__ */ jsx("br", {}),
238
- " Please try again later."
239
- ]
240
- }
241
- ),
242
- /* @__PURE__ */ jsx("div", { style: { textAlign: "center", marginBottom: 12 }, children: /* @__PURE__ */ jsx("button", { className: endChatButtonStyle, onClick: onEndChat, children: "End Chat" }) })
243
- ] }),
244
- msg.event == "chatEnded" && msg.status != "failed" && /* @__PURE__ */ jsxs(Fragment, { children: [
245
- /* @__PURE__ */ jsxs(
246
- "div",
247
- {
248
- title: (/* @__PURE__ */ new Date()).toLocaleString(),
249
- style: {
250
- fontSize: 12,
251
- color: "#888",
252
- marginBottom: 4,
253
- textAlign: "center"
254
- },
255
- children: [
256
- "Thank you for chatting!",
257
- /* @__PURE__ */ jsx("br", {}),
258
- " This conversation has ended."
259
- ]
260
- }
261
- ),
262
- /* @__PURE__ */ jsx("div", { style: { textAlign: "center", marginBottom: 12 }, children: /* @__PURE__ */ jsx("button", { className: endChatButtonStyle, onClick: onEndChat, children: "End Chat" }) })
263
- ] }),
264
- msg.type == "text" && /* @__PURE__ */ jsx(
265
- "div",
266
- {
267
- style: {
268
- textAlign: msg.$userType === "end_user" ? "right" : "left",
269
- fontSize: 12,
270
- color: vars.chatbot.window.timestampColor
271
- },
272
- children: timeText
273
- }
274
- )
275
- ] });
259
+ ]
260
+ }
261
+ );
276
262
  };
277
263
  export {
278
264
  ChatbotMessage