@axos-web-dev/shared-components 2.0.0-dev.3-evo-ui → 2.0.0-dev.30-toast
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/dist/ATMLocator/ATMLocator.js +7 -5
- package/dist/Accordion/Accordion.js +3 -3
- package/dist/AlertBanner/index.js +1 -1
- package/dist/Article/Article.js +1 -1
- package/dist/Auth/ErrorAlert.js +8 -6
- package/dist/Button/Button.js +26 -6
- package/dist/Calculators/AnnualFeeCalculator/index.js +2 -2
- package/dist/Calculators/ApyCalculator/ApyCalculator.css.d.ts +46 -5
- package/dist/Calculators/ApyCalculator/ApyCalculator.css.js +72 -19
- package/dist/Calculators/ApyCalculator/index.js +583 -293
- package/dist/Calculators/ApyCalculatorUserTest/ApyCalculatorUserTest.css.d.ts +95 -0
- package/dist/Calculators/ApyCalculatorUserTest/ApyCalculatorUserTest.css.js +101 -0
- package/dist/Calculators/ApyCalculatorUserTest/index.d.ts +12 -0
- package/dist/Calculators/ApyCalculatorUserTest/index.js +618 -0
- package/dist/Calculators/AxosOneCalculator/BalanceAPYCalculator.css.js +2 -1
- package/dist/Calculators/BuyDownCalculator/index.js +1 -1
- package/dist/Calculators/Calculator.js +19 -7
- package/dist/Calculators/MarginTradingCalculator/index.js +8 -6
- package/dist/Calculators/MarineLoanMonthlyPaymentCalculator/index.js +2 -2
- package/dist/Calculators/MaxLoanCalculator/index.js +2 -2
- package/dist/Calculators/MonthlyPaymentCalculator/index.js +2 -2
- package/dist/Calculators/MonthlyPaymentLVFCalculator/index.js +1 -1
- package/dist/Calculators/calculator.css.d.ts +21 -1
- package/dist/Calculators/calculator.css.js +3 -3
- package/dist/Calculators/index.d.ts +1 -0
- package/dist/Calculators/index.js +2 -0
- package/dist/Carousel/index.js +9 -7
- package/dist/Chatbot/AnimatedGradientBorder.css.d.ts +5 -0
- package/dist/Chatbot/AnimatedGradientBorder.css.js +13 -3
- package/dist/Chatbot/AudioManager.d.ts +19 -0
- package/dist/Chatbot/AudioManager.js +61 -0
- package/dist/Chatbot/Bubble.css.js +1 -0
- package/dist/Chatbot/Bubble.d.ts +1 -0
- package/dist/Chatbot/Bubble.js +3 -12
- package/dist/Chatbot/Chat.js +17 -7
- package/dist/Chatbot/ChatWindow.css.d.ts +8 -0
- package/dist/Chatbot/ChatWindow.css.js +49 -33
- package/dist/Chatbot/ChatWindow.js +459 -366
- package/dist/Chatbot/Chatbot.css.js +0 -1
- package/dist/Chatbot/Chatbot.css.ts.vanilla.css.js +1 -0
- package/dist/Chatbot/Chatbot.d.ts +13 -2
- package/dist/Chatbot/Chatbot.js +200 -84
- package/dist/Chatbot/ChatbotMessage.d.ts +1 -0
- package/dist/Chatbot/ChatbotMessage.js +189 -160
- package/dist/Chatbot/EllipsisAnimation.js +0 -6
- package/dist/Chatbot/ExpandChatToggle.d.ts +8 -0
- package/dist/Chatbot/ExpandChatToggle.js +74 -0
- package/dist/Chatbot/index.js +11 -2
- package/dist/Chatbot/store/chat.d.ts +8 -0
- package/dist/Chatbot/store/chat.js +14 -2
- package/dist/Chatbot/useHeadlessChat.js +1 -2
- package/dist/Chevron/index.js +10 -5
- package/dist/Comparison/Comparison.css.js +3 -2
- package/dist/Comparison/Comparison.js +7 -5
- package/dist/ContentBanner/index.js +1 -1
- package/dist/ExecutiveBio/ExecutiveBio.js +115 -106
- package/dist/ExecutiveBio/ExecutiveBioSet.js +1 -1
- package/dist/FaqAccordion/index.js +8 -6
- package/dist/FooterDisclosure/FooterDisclosure.js +1 -1
- package/dist/FooterSiteMap/AxosBank/FooterSiteMap.js +26 -6
- package/dist/Forms/ApplyNow.js +8 -6
- package/dist/Forms/BoatMooringLocation.d.ts +6 -1
- package/dist/Forms/BoatMooringLocation.js +145 -8
- package/dist/Forms/ContactUsBusiness.js +9 -7
- package/dist/Forms/ContactUsBusinessNameEmail.js +9 -7
- package/dist/Forms/ContactUsNMLSId.js +9 -7
- package/dist/Forms/ContactUsSchwabAAS.d.ts +11 -0
- package/dist/Forms/ContactUsSchwabAAS.js +263 -0
- package/dist/Forms/CpraRequest.js +8 -6
- package/dist/Forms/CraPublicFile.js +9 -7
- package/dist/Forms/EmailOnly.js +10 -8
- package/dist/Forms/FormEnums.js +2 -2
- package/dist/Forms/MortgageRate/MortgageRateForm.js +9 -7
- package/dist/Forms/MortgageRate/MortgageRateWatch.js +8 -6
- package/dist/Forms/MortgageWarehouseLending.d.ts +1 -1
- package/dist/Forms/MortgageWarehouseLending.js +16 -14
- package/dist/Forms/SuccesForm.js +9 -7
- package/dist/Forms/index.d.ts +1 -0
- package/dist/Forms/index.js +2 -0
- package/dist/HeroBanner/HeroBanner.css.d.ts +1 -0
- package/dist/HeroBanner/HeroBanner.css.js +19 -16
- package/dist/HeroBanner/HeroBanner.d.ts +1 -1
- package/dist/HeroBanner/HeroBanner.interface.d.ts +6 -1
- package/dist/HeroBanner/HeroBanner.js +54 -183
- package/dist/HeroBanner/HeroVideoPoster.d.ts +5 -0
- package/dist/HeroBanner/HeroVideoPoster.js +24 -0
- package/dist/HeroBanner/LargeBanner.css.d.ts +110 -0
- package/dist/HeroBanner/LargeBanner.css.js +22 -8
- package/dist/HeroBanner/LargeHeroBanner.d.ts +5 -0
- package/dist/HeroBanner/LargeHeroBanner.js +228 -0
- package/dist/HeroBanner/index.js +3 -2
- package/dist/Hyperlink/index.js +9 -7
- package/dist/IconBillboard/IconBillboard.css.js +2 -1
- package/dist/IconBillboard/IconBillboard.interface.d.ts +2 -0
- package/dist/IconBillboard/IconBillboardSet.js +1 -1
- package/dist/IconBillboard/sections/CallToActionSection.js +3 -1
- package/dist/ImageBillboard/ImageBillboard.interface.d.ts +2 -0
- package/dist/ImageBillboard/ImageBillboard.js +1 -1
- package/dist/ImageBillboard/ImageBillboardSet.d.ts +1 -1
- package/dist/ImageBillboard/ImageBillboardSet.js +4 -1
- package/dist/ImageLink/ImageLink.js +7 -5
- package/dist/ImageLink/ImageLinkSet.js +6 -4
- package/dist/ImageLink/index.js +8 -6
- package/dist/ImageToast/ImageToast.css.d.ts +5 -0
- package/dist/ImageToast/ImageToast.css.js +13 -0
- package/dist/ImageToast/index.d.ts +9 -0
- package/dist/ImageToast/index.js +188 -0
- package/dist/Input/Checkbox.js +2 -2
- package/dist/Input/DownPaymentInput.js +1 -1
- package/dist/Input/Dropdown.js +1 -1
- package/dist/Input/Input.js +1 -1
- package/dist/Input/InputTextArea.js +1 -1
- package/dist/Insight/Featured/CategorySelector.js +8 -6
- package/dist/Insight/Featured/Featured.js +10 -8
- package/dist/Insight/Featured/Header.js +8 -6
- package/dist/LandingPageHeader/LandingPageHeader.js +1 -1
- package/dist/Modal/Modal.js +8 -6
- package/dist/Modal/contextApi/store.d.ts +0 -3
- package/dist/Modal/contextApi/store.js +88 -2
- package/dist/NavigationMenu/AxosALTS/index.js +7 -5
- package/dist/NavigationMenu/AxosAdvisorServices/index.js +0 -1
- package/dist/NavigationMenu/AxosBank/MobileMenu/MobileMenu.js +7 -5
- package/dist/NavigationMenu/AxosBank/MobileMenu/MobileMenu.module.js +27 -27
- package/dist/NavigationMenu/AxosBank/MobileMenu/MobileNavData.d.ts +13 -8
- package/dist/NavigationMenu/AxosBank/MobileMenu/MobileNavData.js +30 -25
- package/dist/NavigationMenu/AxosBank/NavBar.module.js +39 -39
- package/dist/NavigationMenu/AxosBank/SubNavBar.js +78 -41
- package/dist/NavigationMenu/AxosBank/index.js +50 -32
- package/dist/NavigationMenu/AxosFiduciary/NavBar.module.js +40 -43
- package/dist/NavigationMenu/AxosFiduciary/index.js +0 -1
- package/dist/NavigationMenu/LaVictoire/index.js +8 -6
- package/dist/NavigationMenu/Navbar.js +9 -7
- package/dist/NavigationMenu/SignInNavButton.js +10 -8
- package/dist/PageNavItem/PageNavItem.js +1 -1
- package/dist/SetContainer/SetContainer.css.d.ts +1 -0
- package/dist/SetContainer/SetContainer.css.js +5 -3
- package/dist/SetContainer/SetContainer.js +15 -7
- package/dist/SetContainer/index.js +2 -1
- package/dist/SocialMediaBar/iconsRepository.js +8 -6
- package/dist/StepItem/StepItem.js +1 -1
- package/dist/StepItemSet/StepItemSet.js +1 -1
- package/dist/Table/Table.css.d.ts +14 -1
- package/dist/Table/Table.css.js +21 -19
- package/dist/Table/Table.d.ts +1 -1
- package/dist/Table/Table.js +5 -3
- package/dist/Topic/Topic.js +1 -1
- package/dist/TopicalNavItem/TopicalNavItem.css.d.ts +0 -1
- package/dist/TopicalNavItem/TopicalNavItem.css.js +2 -4
- package/dist/TopicalNavItem/TopicalNavItem.js +11 -33
- package/dist/TopicalNavItem/index.js +1 -2
- package/dist/VideoTile/VideoTile.js +7 -5
- package/dist/VideoWrapper/index.js +8 -6
- package/dist/assets/Calculators/ApyCalculator/ApyCalculator.css +350 -64
- package/dist/assets/Calculators/ApyCalculatorUserTest/ApyCalculatorUserTest.css +424 -0
- package/dist/assets/Calculators/AxosOneCalculator/BalanceAPYCalculator.css +2 -2
- package/dist/assets/Calculators/calculator.css +25 -15
- package/dist/assets/Chatbot/AnimatedGradientBorder.css +104 -24
- package/dist/assets/Chatbot/Bubble.css +25 -7
- package/dist/assets/Chatbot/ChatWindow.css +181 -88
- package/dist/assets/Comparison/Comparison.css +2 -2
- package/dist/assets/DownloadTile/DownloadTile.css +7 -0
- package/dist/assets/ExecutiveBio/ExecutiveBio.css +38 -14
- package/dist/assets/HeroBanner/HeroBanner.css +83 -65
- package/dist/assets/HeroBanner/LargeBanner.css +126 -59
- package/dist/assets/IconBillboard/IconBillboard.css +33 -0
- package/dist/assets/ImageBillboard/ImageBillboard.css +1 -1
- package/dist/assets/ImageToast/ImageToast.css +33 -0
- package/dist/assets/NavigationMenu/AxosBank/MobileMenu/MobileMenu.css +49 -49
- package/dist/assets/NavigationMenu/AxosBank/NavBar.css +88 -88
- package/dist/assets/NavigationMenu/AxosFiduciary/NavBar.css +82 -82
- package/dist/assets/SetContainer/SetContainer.css +25 -15
- package/dist/assets/Table/Table.css +85 -76
- package/dist/assets/TextBlock/TextBlock.css +7 -0
- package/dist/assets/TopicalNavItem/TopicalNavItem.css +25 -52
- package/dist/assets/TopicalNavSet/TopicalNavSet.css +29 -4
- package/dist/assets/VideoTile/VideoTile.css +6 -0
- package/dist/assets/globals.css +9 -9
- package/dist/assets/notification.mp3.js +4 -0
- package/dist/assets/themes/axos.css +8 -7
- package/dist/assets/themes/premier.css +9 -8
- package/dist/assets/themes/ufb.css +9 -8
- package/dist/assets/themes/victorie.css +9 -8
- package/dist/main.js +24 -8
- package/dist/themes/axos.css.d.ts +1 -0
- package/dist/themes/axos.css.js +1 -1
- package/dist/utils/allowedAxosDomains.js +2 -1
- package/dist/utils/appendQueryParams.d.ts +3 -1
- package/dist/utils/appendQueryParams.js +66 -66
- package/dist/utils/getPosition.d.ts +1 -0
- package/dist/utils/getPosition.js +17 -0
- package/dist/utils/index.js +3 -1
- package/dist/utils/tealiumOrganicFallback.d.ts +21 -0
- package/dist/utils/tealiumOrganicFallback.js +26 -0
- package/dist/utils/useVisibility.d.ts +1 -0
- package/dist/utils/useVisibility.js +18 -0
- package/dist/utils/variant.types.d.ts +1 -0
- package/dist/vite-env.d.js +1 -0
- package/package.json +148 -148
- package/dist/Chatbot/authenticate.d.ts +0 -3
- package/dist/Chatbot/authenticate.js +0 -16
- package/dist/assets/Chatbot/Chatbot.css +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1,10 +1,21 @@
|
|
|
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;
|
|
4
7
|
};
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
type InitalizeChatbot = {
|
|
9
|
+
companyId: string;
|
|
10
|
+
tenantName: string;
|
|
11
|
+
host: string;
|
|
12
|
+
authUrl: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const Chatbot: ({ project, projectEnv, menuOption, config, }: {
|
|
15
|
+
project?: "axos" | "ufb" | "Axos" | "Ufb";
|
|
7
16
|
projectEnv?: "dev" | "qa" | "uat" | "stg" | "prod";
|
|
8
17
|
menuOption?: "Support Virtual Agent" | string;
|
|
9
18
|
debug?: boolean;
|
|
19
|
+
config: InitalizeChatbot;
|
|
10
20
|
}) => false | import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export {};
|
package/dist/Chatbot/Chatbot.js
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { usePageVisibility } from "../utils/useVisibility.js";
|
|
4
|
+
import { useRef, useState, useEffect } from "react";
|
|
5
|
+
import { useMount, useUnmount } from "react-use";
|
|
6
|
+
import notificationSound from "../assets/notification.mp3.js";
|
|
7
|
+
import AudioManager from "./AudioManager.js";
|
|
4
8
|
import { Bubble } from "./Bubble.js";
|
|
5
|
-
import {
|
|
9
|
+
import { chatbotAXB, chatbotUFB } from "./Chatbot.css.js";
|
|
6
10
|
import { ChatWindow } from "./ChatWindow.js";
|
|
7
11
|
import { useOpenChat } from "./store/chat.js";
|
|
8
12
|
import { useMessages } from "./store/messages.js";
|
|
9
|
-
|
|
10
|
-
|
|
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";
|
|
18
|
+
}
|
|
11
19
|
const Chatbot = ({
|
|
12
20
|
project = "axos",
|
|
13
21
|
projectEnv = "dev",
|
|
14
22
|
menuOption = "Support Virtual Agent",
|
|
15
|
-
|
|
23
|
+
config
|
|
16
24
|
}) => {
|
|
17
25
|
const {
|
|
26
|
+
isOpen,
|
|
18
27
|
hasOpenedOnce,
|
|
19
28
|
toggle,
|
|
20
29
|
reset,
|
|
@@ -22,19 +31,24 @@ const Chatbot = ({
|
|
|
22
31
|
hasEscalated,
|
|
23
32
|
endEscalation,
|
|
24
33
|
unblockInput,
|
|
25
|
-
blockInput
|
|
34
|
+
blockInput,
|
|
35
|
+
hasStarted,
|
|
36
|
+
setChatStarted,
|
|
37
|
+
resetChatStarted,
|
|
38
|
+
setChatStatus,
|
|
39
|
+
displayThankyouMessage,
|
|
40
|
+
hideDisplayThankyouMessage
|
|
26
41
|
} = useOpenChat();
|
|
42
|
+
const isVisible = usePageVisibility();
|
|
27
43
|
const { addMessage, addMessages, clearMessages, messages } = useMessages();
|
|
28
44
|
const clientRef = useRef(null);
|
|
29
45
|
const menuRef = useRef(null);
|
|
30
46
|
const isMountedRef = useRef(false);
|
|
31
|
-
const hasLoadedBefore = useRef(true);
|
|
32
47
|
const chatRef = useRef(null);
|
|
48
|
+
const chatLoading = useRef(false);
|
|
33
49
|
const agent_virtual = useRef(null);
|
|
34
50
|
const [status, setStatus] = useState("idle");
|
|
35
|
-
const [hasStarted, setHasStarted] = useState(false);
|
|
36
51
|
const [menusLoaded, setMenusLoaded] = useState(false);
|
|
37
|
-
const [pendingStart, setPendingStart] = useState(false);
|
|
38
52
|
const [isTyping, setIsTyping] = useState(false);
|
|
39
53
|
const [scalationStarted, setScalationStarted] = useState(false);
|
|
40
54
|
useEffect(() => {
|
|
@@ -63,7 +77,7 @@ const Chatbot = ({
|
|
|
63
77
|
$index: -10,
|
|
64
78
|
$userId: 0
|
|
65
79
|
};
|
|
66
|
-
const custom_data = {
|
|
80
|
+
const custom_data = () => ({
|
|
67
81
|
unsigned: {
|
|
68
82
|
facingBrandId: {
|
|
69
83
|
label: "facingBrandId",
|
|
@@ -80,15 +94,22 @@ const Chatbot = ({
|
|
|
80
94
|
env: {
|
|
81
95
|
label: "env",
|
|
82
96
|
value: projectEnv === "uat" ? "dev" : projectEnv
|
|
97
|
+
},
|
|
98
|
+
url: {
|
|
99
|
+
label: "url",
|
|
100
|
+
value: window.location.href
|
|
83
101
|
}
|
|
84
102
|
}
|
|
85
|
-
};
|
|
103
|
+
});
|
|
86
104
|
const onReadyHandler = async () => {
|
|
87
105
|
console.log("Chat client is ready");
|
|
88
106
|
if (clientRef.current) {
|
|
89
107
|
menuRef.current = await clientRef.current.getMenus();
|
|
90
108
|
setMenusLoaded(true);
|
|
91
109
|
console.log("menus:", menuRef.current);
|
|
110
|
+
if (menuRef.current !== null) {
|
|
111
|
+
await startChat("onReady");
|
|
112
|
+
}
|
|
92
113
|
}
|
|
93
114
|
};
|
|
94
115
|
const onAuthenticatedHandler = async () => {
|
|
@@ -219,20 +240,24 @@ const Chatbot = ({
|
|
|
219
240
|
clientRef.current?.off("chat.connected", onChatConnectedHandler);
|
|
220
241
|
};
|
|
221
242
|
const createClient = async () => {
|
|
222
|
-
const { Client
|
|
223
|
-
if (projectEnv !== "prod" || debug) {
|
|
224
|
-
Logger.addHandler(consoleLoggerHandler);
|
|
225
|
-
}
|
|
243
|
+
const { Client } = await import("@ujet/websdk-headless");
|
|
226
244
|
if (clientRef.current) return;
|
|
227
245
|
const client = new Client({
|
|
228
|
-
companyId:
|
|
229
|
-
tenant:
|
|
230
|
-
host:
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
246
|
+
companyId: config.companyId,
|
|
247
|
+
tenant: config.tenantName,
|
|
248
|
+
host: config.host,
|
|
249
|
+
authenticate: async () => {
|
|
250
|
+
const res = await fetch(config.authUrl, {
|
|
251
|
+
method: "GET",
|
|
252
|
+
headers: {
|
|
253
|
+
"Content-Type": "application/json"
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
const data = await res.json();
|
|
257
|
+
return {
|
|
258
|
+
token: data.token
|
|
259
|
+
};
|
|
260
|
+
}
|
|
236
261
|
});
|
|
237
262
|
client?.on("ready", onReadyHandler);
|
|
238
263
|
client?.on("authenticated", onAuthenticatedHandler);
|
|
@@ -241,59 +266,91 @@ const Chatbot = ({
|
|
|
241
266
|
registerEventHandlers();
|
|
242
267
|
return;
|
|
243
268
|
};
|
|
244
|
-
const startChat = async () => {
|
|
245
|
-
console.log("Starting chat");
|
|
269
|
+
const startChat = async (source) => {
|
|
246
270
|
const client = clientRef.current;
|
|
247
|
-
if (!client)
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
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();
|
|
280
|
+
if (chatLoading.current) {
|
|
281
|
+
console.log(`startChat skipped [${source}] — already in progress`);
|
|
282
|
+
return;
|
|
258
283
|
}
|
|
284
|
+
setChatStatus("connected");
|
|
259
285
|
try {
|
|
286
|
+
console.log(`Starting chat [${source}]`, chatRef.current);
|
|
287
|
+
chatLoading.current = true;
|
|
288
|
+
if (!menuRef.current || !menuRef.current.menus) {
|
|
289
|
+
let waited = 0;
|
|
290
|
+
while ((!menuRef.current || !menuRef.current.menus) && waited < 5e3) {
|
|
291
|
+
await new Promise((res) => setTimeout(res, 100));
|
|
292
|
+
waited += 100;
|
|
293
|
+
}
|
|
294
|
+
if (!menuRef.current || !menuRef.current.menus) {
|
|
295
|
+
console.error("Menu not loaded, cannot start chat");
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
console.log("menus: ->", menuRef.current);
|
|
260
300
|
const ongoingChat = await client.loadOngoingChat();
|
|
301
|
+
console.log("theres a ongoing chat?: -->", ongoingChat);
|
|
261
302
|
if (ongoingChat) {
|
|
262
303
|
console.log("Ongoing chat found:", ongoingChat);
|
|
263
304
|
console.log("Resuming chat:", ongoingChat.id);
|
|
264
|
-
chatRef.current =
|
|
305
|
+
chatRef.current = ongoingChat;
|
|
265
306
|
agent_virtual.current = ongoingChat.agent;
|
|
266
307
|
return;
|
|
267
308
|
}
|
|
309
|
+
console.log("not ongoing chat ");
|
|
310
|
+
console.log(!!ongoingChat);
|
|
268
311
|
const foundMenu = menuRef.current.menus.find(
|
|
269
312
|
(menu) => menu.name === menuOption
|
|
270
313
|
);
|
|
271
314
|
const menuId = foundMenu && foundMenu.id;
|
|
272
315
|
console.log("Creating new chat with menu ID:", menuId);
|
|
273
|
-
|
|
274
|
-
|
|
316
|
+
if (!foundMenu) {
|
|
317
|
+
throw new Error("Menu not found: " + menuOption);
|
|
318
|
+
}
|
|
319
|
+
const newChat = await client.createChat(menuId, {
|
|
320
|
+
custom_data: custom_data()
|
|
321
|
+
});
|
|
322
|
+
if (newChat && typeof newChat === "object" && isChat(newChat)) {
|
|
275
323
|
chatRef.current = newChat;
|
|
276
324
|
agent_virtual.current = newChat.agent;
|
|
277
325
|
console.log("Chat created id:", newChat.id);
|
|
278
326
|
}
|
|
279
327
|
} catch (err) {
|
|
280
328
|
console.error("Error creating chat:", err);
|
|
329
|
+
} finally {
|
|
330
|
+
chatLoading.current = false;
|
|
331
|
+
setChatStarted();
|
|
281
332
|
}
|
|
282
333
|
};
|
|
283
334
|
const handleClick = async () => {
|
|
335
|
+
audioManager.setSoundEnabled(true);
|
|
284
336
|
toggle();
|
|
285
337
|
if (hasStarted) return;
|
|
286
|
-
if (!menusLoaded) {
|
|
287
|
-
setPendingStart(true);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
338
|
if (!hasOpenedOnce) {
|
|
291
|
-
await startChat();
|
|
292
|
-
|
|
339
|
+
await startChat("bubbleClick");
|
|
340
|
+
setChatStarted();
|
|
293
341
|
}
|
|
294
342
|
};
|
|
295
343
|
const onSendMessage = async (msg) => {
|
|
296
|
-
|
|
344
|
+
const clientChatId = clientRef.current?.chat?.id;
|
|
345
|
+
const refChatId = chatRef.current?.id;
|
|
346
|
+
console.log(
|
|
347
|
+
"Sending message:",
|
|
348
|
+
msg,
|
|
349
|
+
"| client.chat.id:",
|
|
350
|
+
clientChatId,
|
|
351
|
+
"| chatRef.id:",
|
|
352
|
+
refChatId
|
|
353
|
+
);
|
|
297
354
|
try {
|
|
298
355
|
await clientRef.current?.sendTextMessage(msg);
|
|
299
356
|
} catch (error) {
|
|
@@ -305,21 +362,33 @@ const Chatbot = ({
|
|
|
305
362
|
}
|
|
306
363
|
};
|
|
307
364
|
const onEndChat = async () => {
|
|
308
|
-
console.log(
|
|
365
|
+
console.log(`Ending chat [end chat]`);
|
|
309
366
|
if (chatRef.current) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
367
|
+
try {
|
|
368
|
+
clientRef.current?.finishChat().then(() => {
|
|
369
|
+
console.log(`Chat finished`);
|
|
370
|
+
chatRef.current?.destroy().then(() => {
|
|
371
|
+
console.log(`Chat destroyed`);
|
|
372
|
+
clearMessages();
|
|
373
|
+
chatRef.current = null;
|
|
374
|
+
resetChatStarted();
|
|
375
|
+
console.log("Chat ended");
|
|
376
|
+
endEscalation?.();
|
|
377
|
+
}).finally(() => {
|
|
378
|
+
setChatStatus("ending");
|
|
379
|
+
displayThankyouMessage();
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
} catch (error) {
|
|
383
|
+
console.log(error, "from onEndChat");
|
|
384
|
+
}
|
|
385
|
+
return;
|
|
317
386
|
}
|
|
318
387
|
};
|
|
319
388
|
const onEndAndStartNewChat = async () => {
|
|
320
389
|
console.log("Ending current chat and starting a new one");
|
|
321
390
|
await onEndChat();
|
|
322
|
-
await startChat();
|
|
391
|
+
await startChat("endAndStartNew");
|
|
323
392
|
};
|
|
324
393
|
useMount(async () => {
|
|
325
394
|
console.log("Chatbot mounted");
|
|
@@ -327,19 +396,12 @@ const Chatbot = ({
|
|
|
327
396
|
isMountedRef.current = true;
|
|
328
397
|
await createClient();
|
|
329
398
|
});
|
|
330
|
-
useEffect(() => {
|
|
331
|
-
if (menusLoaded && pendingStart && !hasStarted) {
|
|
332
|
-
startChat();
|
|
333
|
-
setPendingStart(false);
|
|
334
|
-
}
|
|
335
|
-
}, [menusLoaded, pendingStart, hasStarted]);
|
|
336
399
|
useUnmount(() => {
|
|
337
400
|
console.log("Chatbot unmounted");
|
|
338
401
|
deregisterEventHandlers();
|
|
339
|
-
|
|
340
|
-
hasLoadedBefore.current = true;
|
|
402
|
+
chatLoading.current = false;
|
|
341
403
|
reset();
|
|
342
|
-
|
|
404
|
+
resetChatStarted();
|
|
343
405
|
setStatus("idle");
|
|
344
406
|
clearMessages();
|
|
345
407
|
endEscalation?.();
|
|
@@ -350,9 +412,13 @@ const Chatbot = ({
|
|
|
350
412
|
const onClose = () => {
|
|
351
413
|
toggle();
|
|
352
414
|
};
|
|
353
|
-
const
|
|
415
|
+
const newChatSession = async () => {
|
|
416
|
+
console.log("create new session");
|
|
417
|
+
};
|
|
418
|
+
const onCloseAfterThankYou = async () => {
|
|
354
419
|
reset();
|
|
355
|
-
|
|
420
|
+
resetChatStarted();
|
|
421
|
+
newChatSession();
|
|
356
422
|
};
|
|
357
423
|
const onPreviewTyping = async (msg) => {
|
|
358
424
|
console.log("Preview typing message:", msg);
|
|
@@ -365,25 +431,75 @@ const Chatbot = ({
|
|
|
365
431
|
console.error("Error sending preview message:", error);
|
|
366
432
|
}
|
|
367
433
|
};
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
onClose,
|
|
379
|
-
onNewChat: onEndAndStartNewChat,
|
|
380
|
-
onCloseAfterThankYou,
|
|
381
|
-
previewTyping: onPreviewTyping,
|
|
382
|
-
isTyping
|
|
434
|
+
useEffect(() => {
|
|
435
|
+
if (chatRef.current) {
|
|
436
|
+
if (isVisible && isOpen) {
|
|
437
|
+
audioManager.setSoundEnabled(false);
|
|
438
|
+
}
|
|
439
|
+
if (isVisible && !isOpen) {
|
|
440
|
+
audioManager.setSoundEnabled(true);
|
|
441
|
+
}
|
|
442
|
+
if (!isVisible) {
|
|
443
|
+
audioManager.setSoundEnabled(true);
|
|
383
444
|
}
|
|
384
|
-
|
|
385
|
-
]
|
|
445
|
+
}
|
|
446
|
+
}, [isOpen, isVisible]);
|
|
447
|
+
useMount(() => {
|
|
448
|
+
const hasParams = () => {
|
|
449
|
+
return window.location.search.includes("utm_");
|
|
450
|
+
};
|
|
451
|
+
const tryStart = () => {
|
|
452
|
+
if (hasParams()) {
|
|
453
|
+
startChat("utm-ready");
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
return false;
|
|
457
|
+
};
|
|
458
|
+
if (tryStart()) return;
|
|
459
|
+
const original = history.replaceState;
|
|
460
|
+
history.replaceState = function(...args) {
|
|
461
|
+
original.apply(this, args);
|
|
462
|
+
if (tryStart()) {
|
|
463
|
+
history.replaceState = original;
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
const interval = setInterval(() => {
|
|
467
|
+
if (tryStart()) {
|
|
468
|
+
clearInterval(interval);
|
|
469
|
+
history.replaceState = original;
|
|
470
|
+
}
|
|
471
|
+
}, 100);
|
|
472
|
+
return () => {
|
|
473
|
+
clearInterval(interval);
|
|
474
|
+
history.replaceState = original;
|
|
475
|
+
};
|
|
476
|
+
});
|
|
477
|
+
return menusLoaded && /* @__PURE__ */ jsxs(
|
|
478
|
+
"div",
|
|
479
|
+
{
|
|
480
|
+
className: ["axos", "Axos"].includes(project) ? chatbotAXB : chatbotUFB,
|
|
481
|
+
children: [
|
|
482
|
+
/* @__PURE__ */ jsx(Bubble, { onClick: handleClick, project }),
|
|
483
|
+
/* @__PURE__ */ jsx(
|
|
484
|
+
ChatWindow,
|
|
485
|
+
{
|
|
486
|
+
status,
|
|
487
|
+
virtualAgent: agent_virtual.current,
|
|
488
|
+
messages,
|
|
489
|
+
onSend: onSendMessage,
|
|
490
|
+
endChat: onEndChat,
|
|
491
|
+
onClose,
|
|
492
|
+
onNewChat: onEndAndStartNewChat,
|
|
493
|
+
onCloseAfterThankYou,
|
|
494
|
+
previewTyping: onPreviewTyping,
|
|
495
|
+
isTyping
|
|
496
|
+
}
|
|
497
|
+
)
|
|
498
|
+
]
|
|
499
|
+
}
|
|
500
|
+
);
|
|
386
501
|
};
|
|
387
502
|
export {
|
|
388
|
-
Chatbot
|
|
503
|
+
Chatbot,
|
|
504
|
+
audioManager
|
|
389
505
|
};
|
|
@@ -12,6 +12,7 @@ interface ChatbotMessageProps {
|
|
|
12
12
|
onCancelEndChat?: () => void;
|
|
13
13
|
onSend?: (content: string) => void;
|
|
14
14
|
onEndChat?: () => void;
|
|
15
|
+
inputRef: React.RefObject<HTMLTextAreaElement | null>;
|
|
15
16
|
}
|
|
16
17
|
export declare const ChatbotMessage: FC<ChatbotMessageProps>;
|
|
17
18
|
export {};
|