ss-support-widget 1.0.2 → 1.0.5

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/index.html CHANGED
@@ -4,14 +4,16 @@
4
4
  <meta charset="utf-8" />
5
5
  <title>Widget test</title>
6
6
  </head>
7
- <body>
7
+ <body style="height: 100vh;">
8
+ <div style="height: 600px;">test</div>
9
+ <div style="height: 600px;">test</div>
8
10
  <script>
9
11
  window.ChatBotConfig = {
10
- clientId: "6947078b8b26c4ac8aaaa80f",
12
+ clientId: "694802ab424bd274310d61d8",
11
13
  apiBaseUrl: "https://ai-chatbots-api.azurewebsites.net/",
12
14
  };
13
15
  </script>
14
16
  <script type="module" src="/src/element.tsx"></script>
15
- <!-- <script src="https://cdn.jsdelivr.net/npm/ss-support-widget@1.0.1/dist/chat-bot-widget.js"></script> -->
17
+ <!-- <script src="https://cdn.jsdelivr.net/npm/ss-support-widget@1.0.4/dist/chat-bot-widget.js"></script> -->
16
18
  </body>
17
19
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ss-support-widget",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "description": "Chatbot widget for customer support",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/App.tsx CHANGED
@@ -17,6 +17,7 @@ export default function App({ config }: { config: Config }) {
17
17
  const [threadId, setThreadId] = useState(getThreadId() || config.threadId || "");
18
18
  const [msgs, setMsgs] = useState<Msg[]>([]);
19
19
  const [sending, setSending] = useState(false);
20
+ const [hideChat, setHideChat] = useState(false);
20
21
 
21
22
  const anchorSx = useMemo(
22
23
  () => ({
@@ -29,6 +30,15 @@ export default function App({ config }: { config: Config }) {
29
30
  []
30
31
  );
31
32
 
33
+ useEffect(() => {
34
+ const path = window.location.pathname;
35
+ if (config.hideChatForUrls?.some(u => path.startsWith(u))) {
36
+ setHideChat(true);
37
+ } else {
38
+ setHideChat(false);
39
+ }
40
+ });
41
+
32
42
  useEffect(() => {
33
43
  getHistoryMessages(config,
34
44
  getThreadId() || config.threadId || "",
@@ -81,14 +91,16 @@ export default function App({ config }: { config: Config }) {
81
91
  }
82
92
 
83
93
  return (
84
- <ChatWidget
85
- anchorSx={anchorSx}
86
- open={open}
87
- setOpen={setOpen}
88
- msgs={msgs}
89
- input={input}
90
- setInput={setInput}
91
- send={send}
92
- sending={sending} />
94
+ hideChat
95
+ ? <></>
96
+ : <ChatWidget
97
+ anchorSx={anchorSx}
98
+ open={open}
99
+ setOpen={setOpen}
100
+ msgs={msgs}
101
+ input={input}
102
+ setInput={setInput}
103
+ send={send}
104
+ sending={sending} />
93
105
  );
94
106
  }
@@ -149,9 +149,9 @@ export function ChatWidget({
149
149
  <Box
150
150
  sx={{
151
151
  flex: 1,
152
- minHeight: 0,
152
+ minHeight: 250,
153
153
  position: "relative",
154
- height: 400,
154
+ // height: 300,
155
155
  overflow: "auto",
156
156
  px: 1.5,
157
157
  py: 1.5,
package/src/element.tsx CHANGED
@@ -5,7 +5,7 @@ import { CacheProvider } from "@emotion/react";
5
5
  import { CssBaseline, ThemeProvider, createTheme } from "@mui/material";
6
6
  import App from "./App";
7
7
  import { ensureViewportMeta } from "./hooks";
8
- import { getApiStatus } from "./service";
8
+ import { getApiStatus, getClientActivityStatus, getHideChatForUrls } from "./service";
9
9
 
10
10
  export type Config = {
11
11
  clientId: string;
@@ -13,8 +13,12 @@ export type Config = {
13
13
  threadId?: string;
14
14
  token?: string;
15
15
  userId?: string;
16
+ hideChatForUrls?: string[];
16
17
  };
17
18
 
19
+ const cfg = (window as any).ChatBotConfig;
20
+ const chatBotComponentName = `chat-bot-${cfg.clientId}`;
21
+
18
22
  class ChatBotElement extends HTMLElement {
19
23
  private root?: Root;
20
24
  private mountEl?: HTMLDivElement;
@@ -69,24 +73,28 @@ class ChatBotElement extends HTMLElement {
69
73
  const token = this.getAttribute("token") || raw?.token || undefined;
70
74
  const userId = this.getAttribute("user-id") || raw?.userId || undefined;
71
75
 
76
+ const hideChatForUrls = raw?.hideChatForUrls || []
77
+
72
78
  if (!clientId || !apiBaseUrl) return null;
73
- return { clientId, apiBaseUrl, threadId, token, userId };
79
+ return { clientId, apiBaseUrl, threadId, token, userId, hideChatForUrls };
74
80
  }
75
81
  }
76
82
 
77
- if (!customElements.get("chat-bot")) {
78
- customElements.define("chat-bot", ChatBotElement);
83
+ if (!customElements.get(chatBotComponentName)) {
84
+ customElements.define(chatBotComponentName, ChatBotElement);
79
85
  }
80
86
 
81
87
  (async function autoMount() {
82
- const cfg = (window as any).ChatBotConfig;
83
88
  if (!cfg) return;
84
- if (document.querySelector("chat-bot")) return;
89
+ if (document.querySelector(chatBotComponentName)) return;
85
90
 
86
91
  var isHealty = await getApiStatus(cfg)
92
+ if (!isHealty) return;
87
93
 
88
- if(!isHealty) return;
94
+ var isClientActive = await getClientActivityStatus(cfg)
95
+ if (!isClientActive) return;
89
96
 
90
- const el = document.createElement("chat-bot");
97
+ cfg.hideChatForUrls = await getHideChatForUrls(cfg)
98
+ const el = document.createElement(chatBotComponentName);
91
99
  document.body.appendChild(el);
92
100
  })();
package/src/service.ts CHANGED
@@ -36,3 +36,33 @@ export async function getApiStatus(config: Config): Promise<boolean> {
36
36
 
37
37
  return res.ok;
38
38
  }
39
+
40
+ export async function getClientActivityStatus(config: Config): Promise<boolean> {
41
+
42
+ const res = await fetch(config.apiBaseUrl + "api/client-activity-status", {
43
+ method: "GET",
44
+ headers: {
45
+ "Content-Type": "application/json",
46
+ ...(config.clientId ? { "X-Client-Id": config.clientId } : {}),
47
+ },
48
+ });
49
+
50
+ if (!res.ok) {
51
+ return false;
52
+ }
53
+
54
+ return res.body ? await res.json() as boolean : false;
55
+ }
56
+
57
+ export async function getHideChatForUrls(config: Config): Promise<string[]> {
58
+
59
+ const res = await fetch(config.apiBaseUrl + "api/hide-chat-for", {
60
+ method: "GET",
61
+ headers: {
62
+ "Content-Type": "application/json",
63
+ ...(config.clientId ? { "X-Client-Id": config.clientId } : {}),
64
+ },
65
+ });
66
+
67
+ return res.body ? await res.json() as string[] : [];
68
+ }
@@ -5,3 +5,13 @@ export function saveThreadId(threadId: string) {
5
5
  export function getThreadId() : string | null {
6
6
  return sessionStorage.getItem("threadId");
7
7
  }
8
+
9
+
10
+ // export function saveUrlPaths(urls: string[]) {
11
+ // sessionStorage.setItem("urlPaths", JSON.stringify(urls));
12
+ // }
13
+
14
+ // export function getUrlPaths() : string[] | [] {
15
+ // const item = sessionStorage.getItem("urlPaths");
16
+ // return item ? JSON.parse(item) : [];
17
+ // }