@axos-web-dev/shared-components 1.0.100-dev.61 → 1.0.100-dev.62-0

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.
@@ -24,6 +24,8 @@ interface ChatWindowProps {
24
24
  showName?: boolean;
25
25
  onNewChat?: () => void;
26
26
  onCloseAfterThankYou?: () => void;
27
+ isTyping?: boolean;
28
+ previewTyping?: (msg: string) => void;
27
29
  }
28
30
  export declare const ChatWindow: React.FC<ChatWindowProps>;
29
31
  export {};
@@ -32,6 +32,9 @@ const ChatWindow = ({
32
32
  showName = false,
33
33
  onCloseAfterThankYou = () => {
34
34
  console.log("Close after thank you");
35
+ },
36
+ previewTyping = (msg) => {
37
+ console.log("Preview typing: ", msg);
35
38
  }
36
39
  }) => {
37
40
  const { showThankyouMessage, displayThankyouMessage, toggleThankyouMessage } = useOpenChat();
@@ -86,6 +89,24 @@ const ChatWindow = ({
86
89
  setInput("");
87
90
  toggleThankyouMessage?.();
88
91
  };
92
+ useEffect(() => {
93
+ const scalationStarted = messages.some(
94
+ (msg) => msg.$userType === "user" || ["escalationAccepted", "escalationStarted"].includes(
95
+ msg.event
96
+ )
97
+ );
98
+ if (!scalationStarted) {
99
+ return;
100
+ }
101
+ const sendPreview = () => {
102
+ const cleaned = cleanInput(input);
103
+ previewTyping(cleaned);
104
+ };
105
+ const intervalId = setInterval(sendPreview, 2e3);
106
+ return () => {
107
+ clearInterval(intervalId);
108
+ };
109
+ }, [input, messages, previewTyping]);
89
110
  return /* @__PURE__ */ jsxs("div", { className: clsx(windowStyle, isOpen && windowOpenStyle), children: [
90
111
  /* @__PURE__ */ jsxs("div", { className: windowBarStyle, children: [
91
112
  /* @__PURE__ */ jsx("div", { className: clsx(left_bar_section) }),
@@ -136,6 +157,7 @@ const ChatWindow = ({
136
157
  /* @__PURE__ */ jsx(
137
158
  "button",
138
159
  {
160
+ disabled: messages.length === 0,
139
161
  onClick: () => {
140
162
  setMenuOpen(!menuOpen);
141
163
  },
@@ -417,7 +439,11 @@ const ChatWindow = ({
417
439
  showAvatar,
418
440
  showName,
419
441
  virtualAgent,
420
- onCancelEndChat
442
+ onCancelEndChat,
443
+ onEndChat: () => {
444
+ endChat();
445
+ onCloseAfterThankYou();
446
+ }
421
447
  },
422
448
  msg?.$index
423
449
  )),
@@ -6,7 +6,7 @@ import { chatbotUFB, chatbotAXB } from "./Chatbot.css.js";
6
6
  import { ChatWindow } from "./ChatWindow.js";
7
7
  import { useOpenChat } from "./store/chat.js";
8
8
  import { useMessages } from "./store/messages.js";
9
- import { useRef, useState, useEffect } from "react";
9
+ import { useRef, useState, useEffect, useCallback } from "react";
10
10
  import { useMount, useUnmount } from "react-use";
11
11
  const Chatbot = ({
12
12
  project = "axos",
@@ -26,6 +26,20 @@ const Chatbot = ({
26
26
  const [hasStarted, setHasStarted] = useState(false);
27
27
  const [menusLoaded, setMenusLoaded] = useState(false);
28
28
  const [pendingStart, setPendingStart] = useState(false);
29
+ const [isTyping, setIsTyping] = useState(false);
30
+ const [scalationStarted, setScalationStarted] = useState(false);
31
+ useEffect(() => {
32
+ if (messages.length === 0) return;
33
+ const hasScalation = messages.some(
34
+ (msg) => msg.$userType === "user" || ["escalationAccepted", "escalationStarted"].includes(
35
+ msg.event
36
+ )
37
+ );
38
+ setScalationStarted(hasScalation);
39
+ return () => {
40
+ setScalationStarted(false);
41
+ };
42
+ }, [messages]);
29
43
  const brandMap = /* @__PURE__ */ new Map([
30
44
  ["axos", 1],
31
45
  ["ufb", 3]
@@ -33,8 +47,7 @@ const Chatbot = ({
33
47
  const typingMessage = {
34
48
  $sid: "typing-1",
35
49
  type: "system",
36
- // or a custom type like "typing"
37
- text: "AI is typing...",
50
+ text: scalationStarted ? "Typing" : "AI is typing...",
38
51
  sender: { id: "system", type: "system" },
39
52
  $timestamp: /* @__PURE__ */ new Date(),
40
53
  $userType: "system",
@@ -78,12 +91,31 @@ const Chatbot = ({
78
91
  const onChatMessageHandler = async (message) => {
79
92
  console.log("Received message:", message);
80
93
  addMessage(message);
81
- if (!["virtual_agent", "system"].includes(message.$userType)) {
82
- addMessage(typingMessage);
94
+ const eventName = message?.event;
95
+ switch (eventName) {
96
+ case "escalationAccepted":
97
+ setScalationStarted(true);
98
+ return;
99
+ case "escalationStarted":
100
+ setScalationStarted(true);
101
+ return;
102
+ default:
103
+ if (["end_user"].includes(message.$userType)) {
104
+ console.log("ai thiunk", message?.$userType, scalationStarted);
105
+ if (!scalationStarted) {
106
+ addMessage(typingMessage);
107
+ }
108
+ }
109
+ return;
83
110
  }
84
111
  };
85
112
  const onChatTypingStartedHandler = async (identity) => {
86
113
  console.log("Typing started by:", identity);
114
+ setIsTyping(true);
115
+ };
116
+ const onChatTypingEndedHandler = async (identity) => {
117
+ console.log("Typing ended by:", identity);
118
+ setIsTyping(false);
87
119
  };
88
120
  const onChatDisconnectedHandler = async () => {
89
121
  console.log("Chat disconnected");
@@ -111,12 +143,20 @@ const Chatbot = ({
111
143
  const messages2 = await clientRef.current?.fetchMessages();
112
144
  if (messages2) {
113
145
  addMessages(messages2);
146
+ setScalationStarted(
147
+ messages2.some(
148
+ (msg) => msg.$userType === "user" || ["escalationAccepted", "escalationStarted"].includes(
149
+ msg.event
150
+ )
151
+ )
152
+ );
114
153
  }
115
154
  };
116
155
  const registerEventHandlers = () => {
117
156
  clientRef.current?.on("chat.ongoing", onChatOngoingHandler);
118
157
  clientRef.current?.on("chat.message", onChatMessageHandler);
119
158
  clientRef.current?.on("chat.typingStarted", onChatTypingStartedHandler);
159
+ clientRef.current?.on("chat.typingEnded", onChatTypingEndedHandler);
120
160
  clientRef.current?.on("chat.disconnected", onChatDisconnectedHandler);
121
161
  clientRef.current?.on("chat.dismissed", onDismissedHandler);
122
162
  clientRef.current?.on("chat.timeout", onTimeoutHandler);
@@ -131,6 +171,7 @@ const Chatbot = ({
131
171
  clientRef.current?.off("chat.ongoing", onDismissedHandler);
132
172
  clientRef.current?.off("chat.message", onChatMessageHandler);
133
173
  clientRef.current?.off("chat.typingStarted", onChatTypingStartedHandler);
174
+ clientRef.current?.off("chat.typingEnded", onChatTypingEndedHandler);
134
175
  clientRef.current?.off("chat.disconnected", onChatDisconnectedHandler);
135
176
  clientRef.current?.off("chat.dismissed", onDismissedHandler);
136
177
  clientRef.current?.off("chat.timeout", onTimeoutHandler);
@@ -150,6 +191,9 @@ const Chatbot = ({
150
191
  tenant: process.env.CCAI_TENANT_NAME || "",
151
192
  host: process.env.CCAI_HOST || "",
152
193
  // or your region
194
+ // companyId: import.meta.env.VITE_COMPANY_ID || "",
195
+ // tenant: import.meta.env.VITE_TENANT_NAME || "",
196
+ // host: import.meta.env.VITE_HOST || "", // or your region
153
197
  authenticate
154
198
  });
155
199
  client?.on("ready", onReadyHandler);
@@ -210,7 +254,7 @@ const Chatbot = ({
210
254
  setHasStarted(true);
211
255
  }
212
256
  };
213
- const onSendMessage = (msg) => {
257
+ const onSendMessage = async (msg) => {
214
258
  console.log("Sending message:", msg);
215
259
  clientRef.current?.sendTextMessage(msg);
216
260
  };
@@ -262,6 +306,16 @@ const Chatbot = ({
262
306
  reset();
263
307
  setHasStarted(false);
264
308
  };
309
+ const onPreviewTyping = useCallback(async (msg) => {
310
+ console.log("Preview typing message:", msg);
311
+ try {
312
+ if (clientRef.current) {
313
+ clientRef.current?.sendPreviewMessage(msg);
314
+ }
315
+ } catch (error) {
316
+ console.error("Error sending preview message:", error);
317
+ }
318
+ }, []);
265
319
  return /* @__PURE__ */ jsxs("div", { className: project === "ufb" ? chatbotUFB : chatbotAXB, children: [
266
320
  /* @__PURE__ */ jsx(Bubble, { onClick: handleClick }),
267
321
  /* @__PURE__ */ jsx(
@@ -274,7 +328,9 @@ const Chatbot = ({
274
328
  endChat: onEndChat,
275
329
  onClose,
276
330
  onNewChat: onEndAndStartNewChat,
277
- onCloseAfterThankYou
331
+ onCloseAfterThankYou,
332
+ previewTyping: onPreviewTyping,
333
+ isTyping
278
334
  }
279
335
  )
280
336
  ] });
@@ -11,6 +11,7 @@ interface ChatbotMessageProps {
11
11
  virtualAgent?: VirtualAgent | null;
12
12
  onCancelEndChat?: () => void;
13
13
  onSend?: (content: string) => void;
14
+ onEndChat?: () => void;
14
15
  }
15
16
  export declare const ChatbotMessage: FC<ChatbotMessageProps>;
16
17
  export {};
@@ -24,6 +24,7 @@ const ChatbotMessage = ({
24
24
  showName,
25
25
  virtualAgent,
26
26
  onCancelEndChat,
27
+ onEndChat,
27
28
  onSend
28
29
  }) => {
29
30
  const [timeText, setTimeText] = useState(timeAgo(msg.$timestamp));
@@ -196,7 +197,7 @@ const ChatbotMessage = ({
196
197
  ]
197
198
  }
198
199
  ),
199
- /* @__PURE__ */ jsx("div", { style: { textAlign: "center", marginBottom: 12 }, children: /* @__PURE__ */ jsx("button", { className: endChatButtonStyle, onClick: onCancelEndChat, children: "End Chat" }) })
200
+ /* @__PURE__ */ jsx("div", { style: { textAlign: "center", marginBottom: 12 }, children: /* @__PURE__ */ jsx("button", { className: endChatButtonStyle, onClick: onEndChat, children: "End Chat" }) })
200
201
  ] }),
201
202
  msg.type == "text" && /* @__PURE__ */ jsx(
202
203
  "div",
@@ -43,7 +43,8 @@ const moreDomains = {
43
43
  "{MODELSELECTION}": process.env.MODEL_SELECTION_URL || "https://modelselection.axos.com",
44
44
  "{COMMERCIALPORTAL_LOGIN}": `${process.env.COMMERCIALPORTAL_URL}/login` || "https://portals.axosbank.com/login",
45
45
  "{COMMERCIALPORTAL_REGISTER}": process.env.COMMERCIALPORTAL_URL + "/Register" || "https://portals.axosbank.com/Register",
46
- "{SHAREAXB}": process.env.SHAREAXB_URL || "https://share.axosbank.com"
46
+ "{SHAREAXB}": process.env.SHAREAXB_URL || "https://share.axosbank.com",
47
+ "{MERIDIAN}": process.env.MERIDIAN_URL || "https://www.axosbank.com/"
47
48
  };
48
49
  const isAllowedUrl = (url) => {
49
50
  const uri = new URL(url, location.href);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@axos-web-dev/shared-components",
3
3
  "description": "Axos shared components library for web.",
4
- "version": "1.0.100-dev.61",
4
+ "version": "1.0.100-dev.62-0",
5
5
  "type": "module",
6
6
  "module": "dist/main.js",
7
7
  "types": "dist/main.d.ts",