ss-support-widget 1.0.0 → 1.0.2
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/chat-bot-widget.js +59 -341
- package/index.html +3 -2
- package/package.json +2 -2
- package/src/App.tsx +1 -1
- package/src/element.tsx +6 -1
- package/src/service.ts +13 -1
- package/vite.config.ts +3 -0
package/index.html
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
<body>
|
|
8
8
|
<script>
|
|
9
9
|
window.ChatBotConfig = {
|
|
10
|
-
clientId: "
|
|
11
|
-
apiBaseUrl: "
|
|
10
|
+
clientId: "6947078b8b26c4ac8aaaa80f",
|
|
11
|
+
apiBaseUrl: "https://ai-chatbots-api.azurewebsites.net/",
|
|
12
12
|
};
|
|
13
13
|
</script>
|
|
14
14
|
<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> -->
|
|
15
16
|
</body>
|
|
16
17
|
</html>
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ss-support-widget",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Chatbot widget for customer support",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"build:script": "tsup src/element.tsx --format iife --global-name ChatBot --minify --clean --out-dir dist"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [],
|
|
10
10
|
"author": "SS SRL",
|
package/src/App.tsx
CHANGED
|
@@ -62,7 +62,7 @@ export default function App({ config }: { config: Config }) {
|
|
|
62
62
|
|
|
63
63
|
try {
|
|
64
64
|
await streamChat({
|
|
65
|
-
url: config.apiBaseUrl + "/chat-support",
|
|
65
|
+
url: config.apiBaseUrl + "api/chat-support",
|
|
66
66
|
token: config.token,
|
|
67
67
|
clientId: config.clientId,
|
|
68
68
|
threadId: threadId,
|
package/src/element.tsx
CHANGED
|
@@ -5,6 +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
9
|
|
|
9
10
|
export type Config = {
|
|
10
11
|
clientId: string;
|
|
@@ -77,11 +78,15 @@ if (!customElements.get("chat-bot")) {
|
|
|
77
78
|
customElements.define("chat-bot", ChatBotElement);
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
(function autoMount() {
|
|
81
|
+
(async function autoMount() {
|
|
81
82
|
const cfg = (window as any).ChatBotConfig;
|
|
82
83
|
if (!cfg) return;
|
|
83
84
|
if (document.querySelector("chat-bot")) return;
|
|
84
85
|
|
|
86
|
+
var isHealty = await getApiStatus(cfg)
|
|
87
|
+
|
|
88
|
+
if(!isHealty) return;
|
|
89
|
+
|
|
85
90
|
const el = document.createElement("chat-bot");
|
|
86
91
|
document.body.appendChild(el);
|
|
87
92
|
})();
|
package/src/service.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Config } from "./element";
|
|
|
2
2
|
import { MsgDelta } from "./MsgDelta";
|
|
3
3
|
|
|
4
4
|
export async function getHistoryMessages(config: Config, threadId: string, onSucces: (delta: MsgDelta[]) => void): Promise<void> {
|
|
5
|
-
fetch(config.apiBaseUrl + "/chat-support-history", {
|
|
5
|
+
fetch(config.apiBaseUrl + "api/chat-support-history", {
|
|
6
6
|
method: "GET",
|
|
7
7
|
headers: {
|
|
8
8
|
"Content-Type": "application/json",
|
|
@@ -22,5 +22,17 @@ export async function getHistoryMessages(config: Config, threadId: string, onSuc
|
|
|
22
22
|
.catch(err => {
|
|
23
23
|
console.error(err);
|
|
24
24
|
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function getApiStatus(config: Config): Promise<boolean> {
|
|
28
|
+
|
|
29
|
+
const res = await fetch(config.apiBaseUrl + "api/health", {
|
|
30
|
+
method: "GET",
|
|
31
|
+
headers: {
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
...(config.clientId ? { "X-Client-Id": config.clientId } : {}),
|
|
34
|
+
},
|
|
35
|
+
});
|
|
25
36
|
|
|
37
|
+
return res.ok;
|
|
26
38
|
}
|