chatbot-web-sdk 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # chatbot-web-sdk
2
+
3
+ Lightweight web SDK to load the Avya chatbot widget in React, Next.js, Nuxt, and plain JavaScript applications.
4
+
5
+ <p align="center">
6
+ <img src="./assets/readme.png" alt="Chatbot Preview" />
7
+ </p>
8
+
9
+ ## Features
10
+
11
+ - Single config object setup
12
+ - Supports React, Next.js, Nuxt, and plain JS
13
+ - Automatically injects the widget script only once
14
+ - Runtime config updates with `updateChatWidgetConfig`
15
+ - Optional widget cleanup with `destroyChatWidget`
16
+ - Works with both JavaScript and TypeScript projects
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install chatbot-web-sdk
22
+ ```
23
+
24
+ ## API Key Configuration
25
+
26
+ This package requires a valid API key to enable AI-powered chatbot functionality.
27
+
28
+ To obtain the customized API key, please visit `https://chat.avya.lk/` and register there. For further information, please contact through `https://avya.lk/contact-us/`.
29
+
30
+ ## Configuration Options
31
+
32
+ You can also select and manage these configurations from the Playground section in `https://chat.avya.lk/`.
33
+
34
+ | Property | Type | Default | Description |
35
+ | --- | --- | --- | --- |
36
+ | `title` | `string` | required | Title displayed in the chat header |
37
+ | `themeColor` | `string` | `#007BFF` | Primary color for the chat widget |
38
+ | `initialMessage` | `string` | `Hi! How can I help you today?` | Bot's greeting message |
39
+ | `apiKey` | `string` | `""` | API key for backend authentication |
40
+ | `profilePicUrl` | `string` | `null` | URL for bot profile image |
41
+
42
+ ## Nuxt (TypeScript Plugin)
43
+
44
+ Create `plugins/chat-widget.client.ts`:
45
+
46
+ ```ts
47
+ import { createNuxtChatWidgetPlugin } from "chatbot-web-sdk/nuxt";
48
+
49
+ export default defineNuxtPlugin(
50
+ createNuxtChatWidgetPlugin({
51
+ title: "My ChatBot test",
52
+ themeColor: "#D91D1D",
53
+ initialMessage: "Hi! How can I help you today?",
54
+ profilePicUrl: "https://chat.avya.lk/images/logo.webp",
55
+ apiKey: "<YOUR_API_KEY>",
56
+ })
57
+ );
58
+ ```
59
+
60
+ ## Nuxt (JavaScript Plugin)
61
+
62
+ Create `plugins/chat-widget.client.js`:
63
+
64
+ ```js
65
+ import { createNuxtChatWidgetPlugin } from "chatbot-web-sdk/nuxt";
66
+
67
+ export default defineNuxtPlugin(
68
+ createNuxtChatWidgetPlugin({
69
+ title: "My ChatBot test",
70
+ themeColor: "#D91D1D",
71
+ initialMessage: "Hi! How can I help you today?",
72
+ profilePicUrl: "https://chat.avya.lk/images/logo.webp",
73
+ apiKey: "<YOUR_API_KEY>",
74
+ })
75
+ );
76
+ ```
77
+
78
+ ## Nuxt (Vue `app.vue`)
79
+
80
+ ```vue
81
+ <script setup>
82
+ import { onMounted } from "vue";
83
+ import { initChatWidget } from "chatbot-web-sdk";
84
+
85
+ const config = {
86
+ title: "My ChatBot test",
87
+ themeColor: "#D91D1D",
88
+ initialMessage: "Hi! How can I help you today?",
89
+ profilePicUrl: "https://chat.avya.lk/images/logo.webp",
90
+ apiKey: "<YOUR_API_KEY>",
91
+ };
92
+
93
+ onMounted(() => {
94
+ initChatWidget(config);
95
+ });
96
+ </script>
97
+
98
+ <template>
99
+ <div>Nuxt App</div>
100
+ </template>
101
+ ```
102
+
103
+ ## React (TSX)
104
+
105
+ ```tsx
106
+ import { useChatWidget } from "chatbot-web-sdk/react";
107
+ import type { ChatConfig } from "chatbot-web-sdk";
108
+
109
+ const config: ChatConfig = {
110
+ title: "My ChatBot test",
111
+ themeColor: "#D91D1D",
112
+ initialMessage: "Hi! How can I help you today?",
113
+ profilePicUrl: "https://chat.avya.lk/images/logo.webp",
114
+ apiKey: "<YOUR_API_KEY>",
115
+ };
116
+
117
+ export default function App() {
118
+ useChatWidget(config);
119
+ return <div>React App</div>;
120
+ }
121
+ ```
122
+
123
+ ## React (JSX)
124
+
125
+ ```jsx
126
+ import { useChatWidget } from "chatbot-web-sdk/react";
127
+
128
+ const config = {
129
+ title: "My ChatBot test",
130
+ themeColor: "#D91D1D",
131
+ initialMessage: "Hi! How can I help you today?",
132
+ profilePicUrl: "https://chat.avya.lk/images/logo.webp",
133
+ apiKey: "<YOUR_API_KEY>",
134
+ };
135
+
136
+ export default function App() {
137
+ useChatWidget(config);
138
+ return <div>React App</div>;
139
+ }
140
+ ```
141
+
142
+ ## React (Next.js App Router)
143
+
144
+ ```jsx
145
+ "use client";
146
+
147
+ import { useChatWidget } from "chatbot-web-sdk/react";
148
+
149
+ const config = {
150
+ title: "My ChatBot test",
151
+ themeColor: "#D91D1D",
152
+ initialMessage: "Hi! How can I help you today?",
153
+ profilePicUrl: "https://chat.avya.lk/images/logo.webp",
154
+ apiKey: "<YOUR_API_KEY>",
155
+ };
156
+
157
+ export default function Page() {
158
+ useChatWidget(config);
159
+ return <div>Next App</div>;
160
+ }
161
+ ```
162
+
163
+ For more references and code guidance for other languages, please visit `https://chat.avya.lk/`.
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ // src/core.ts
4
+ var DEFAULT_SCRIPT_ID = "chat-widget-script";
5
+ var DEFAULT_SCRIPT_SRC = "https://chatbot.avya.lk/chatbot-assistant";
6
+ var currentScriptId = DEFAULT_SCRIPT_ID;
7
+ function isBrowser() {
8
+ return typeof window !== "undefined" && typeof document !== "undefined";
9
+ }
10
+ function upsertScript(scriptSrc, scriptId, forceReload = false) {
11
+ const existing = document.getElementById(scriptId);
12
+ if (existing && !forceReload) {
13
+ return existing;
14
+ }
15
+ if (existing && forceReload) {
16
+ existing.remove();
17
+ }
18
+ const script = document.createElement("script");
19
+ script.id = scriptId;
20
+ script.src = scriptSrc;
21
+ script.async = true;
22
+ document.body.appendChild(script);
23
+ return script;
24
+ }
25
+ function initChatWidget(config, options = {}) {
26
+ if (!isBrowser()) return null;
27
+ const scriptSrc = options.scriptSrc ?? DEFAULT_SCRIPT_SRC;
28
+ const scriptId = options.scriptId ?? DEFAULT_SCRIPT_ID;
29
+ currentScriptId = scriptId;
30
+ window.ChatWidgetConfig = normalizeConfig(config);
31
+ return upsertScript(scriptSrc, scriptId, options.forceReload ?? false);
32
+ }
33
+ function updateChatWidgetConfig(partialConfig) {
34
+ if (!isBrowser()) return;
35
+ const current = window.ChatWidgetConfig;
36
+ const nextProfilePic = partialConfig.profilePic ?? partialConfig.profilePicUrl ?? current?.profilePic ?? "";
37
+ window.ChatWidgetConfig = {
38
+ title: partialConfig.title ?? current?.title ?? "",
39
+ initialMessage: partialConfig.initialMessage ?? current?.initialMessage ?? "",
40
+ profilePic: nextProfilePic,
41
+ themeColor: partialConfig.themeColor ?? current?.themeColor ?? "",
42
+ apiKey: partialConfig.apiKey ?? current?.apiKey ?? ""
43
+ };
44
+ }
45
+ function destroyChatWidget(scriptId = currentScriptId) {
46
+ if (!isBrowser()) return;
47
+ const script = document.getElementById(scriptId);
48
+ if (script) script.remove();
49
+ delete window.ChatWidgetConfig;
50
+ const widgetRoot = document.getElementById("chat-widget-root");
51
+ if (widgetRoot) widgetRoot.remove();
52
+ }
53
+ function normalizeConfig(config) {
54
+ return {
55
+ title: config.title,
56
+ initialMessage: config.initialMessage,
57
+ profilePic: config.profilePic ?? config.profilePicUrl ?? "",
58
+ themeColor: config.themeColor,
59
+ apiKey: config.apiKey
60
+ };
61
+ }
62
+
63
+ // src/adapters/nuxt.ts
64
+ function createNuxtChatWidgetPlugin(config, options) {
65
+ return () => {
66
+ initChatWidget(config, options);
67
+ };
68
+ }
69
+
70
+ exports.createNuxtChatWidgetPlugin = createNuxtChatWidgetPlugin;
71
+ exports.destroyChatWidget = destroyChatWidget;
72
+ exports.initChatWidget = initChatWidget;
73
+ exports.updateChatWidgetConfig = updateChatWidgetConfig;
74
+ //# sourceMappingURL=nuxt.cjs.map
75
+ //# sourceMappingURL=nuxt.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core.ts","../../src/adapters/nuxt.ts"],"names":[],"mappings":";;;AAEA,IAAM,iBAAA,GAAoB,oBAAA;AAC1B,IAAM,kBAAA,GAAqB,2CAAA;AAE3B,IAAI,eAAA,GAAkB,iBAAA;AAEtB,SAAS,SAAA,GAAY;AACnB,EAAA,OAAO,OAAO,MAAA,KAAW,WAAA,IAAe,OAAO,QAAA,KAAa,WAAA;AAC9D;AAEA,SAAS,YAAA,CAAa,SAAA,EAAmB,QAAA,EAAkB,WAAA,GAAc,KAAA,EAAO;AAC9E,EAAA,MAAM,QAAA,GAAW,QAAA,CAAS,cAAA,CAAe,QAAQ,CAAA;AAEjD,EAAA,IAAI,QAAA,IAAY,CAAC,WAAA,EAAa;AAC5B,IAAA,OAAO,QAAA;AAAA,EACT;AAEA,EAAA,IAAI,YAAY,WAAA,EAAa;AAC3B,IAAA,QAAA,CAAS,MAAA,EAAO;AAAA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A,EAAQ,aAAA,CAAc,MAAA,IAAU,OAAA,EAAS,MAAA,IAAU;AAAA,GACrD;AACF;AAEO,SAAS,iBAAA,CAAkB,WAAW,eAAA,EAAiB;AAC5D,EAAA,IAAI,CAAC,WAAU,EAAG;AAElB,EAAA,MAAM,MAAA,GAAS,QAAA,CAAS,cAAA,CAAe,QAAQ,CAAA;AAC/C,EAAA,IAAI,MAAA,SAAe,MAAA,EAAO;AAE1B,EAAA,OAAO,MAAA,CAAO,gBAAA;AAEd,EAAA,MAAM,UAAA,GAAa,QAAA,CAAS,cAAA,CAAe,kBAAkB,CAAA;AAC7D,EAAA,IAAI,UAAA,aAAuB,MAAA,EAAO;AACpC;AAIA,SAAS,gBAAgB,MAAA,EAA4C;AACnE,EAAA,OAAO;AAAA,IACL,OAAO,MAAA,CAAO,KAAA;AAAA,IACd,gBAAgB,MAAA,CAAO,cAAA;AAAA,IACvB,UAAA,EAAY,MAAA,CAAO,UAAA,IAAc,MAAA,CAAO,aAAA,IAAiB,EAAA;AAAA,IACzD,YAAY,MAAA,CAAO,UAAA;AAAA,IACnB,QAAQ,MAAA,CAAO;AAAA,GACjB;AACF;;;ACjFO,SAAS,0BAAA,CAA2B,QAAoB,OAAA,EAAuB;AACpF,EAAA,OAAO,MAAM;AACX,IAAA,cAAA,CAAe,QAAQ,OAAO,CAAA;AAAA,EAChC,CAAA;AACF","file":"nuxt.cjs","sourcesContent":["import type { ChatConfig, InitOptions, WindowChatWidgetConfig } from \"./types\";\n\nconst DEFAULT_SCRIPT_ID = \"chat-widget-script\";\nconst DEFAULT_SCRIPT_SRC = \"https://chatbot.avya.lk/chatbot-assistant\";\n\nlet currentScriptId = DEFAULT_SCRIPT_ID;\n\nfunction isBrowser() {\n return typeof window !== \"undefined\" && typeof document !== \"undefined\";\n}\n\nfunction upsertScript(scriptSrc: string, scriptId: string, forceReload = false) {\n const existing = document.getElementById(scriptId) as HTMLScriptElement | null;\n\n if (existing && !forceReload) {\n return existing;\n }\n\n if (existing && forceReload) {\n existing.remove();\n }\n\n const script = document.createElement(\"script\");\n script.id = scriptId;\n script.src = scriptSrc;\n script.async = true;\n document.body.appendChild(script);\n\n return script;\n}\n\nexport function initChatWidget(config: ChatConfig, options: InitOptions = {}) {\n if (!isBrowser()) return null;\n\n const scriptSrc = options.scriptSrc ?? DEFAULT_SCRIPT_SRC;\n const scriptId = options.scriptId ?? DEFAULT_SCRIPT_ID;\n currentScriptId = scriptId;\n\n window.ChatWidgetConfig = normalizeConfig(config);\n\n return upsertScript(scriptSrc, scriptId, options.forceReload ?? false);\n}\n\nexport function updateChatWidgetConfig(partialConfig: Partial<ChatConfig>) {\n if (!isBrowser()) return;\n\n const current = window.ChatWidgetConfig;\n const nextProfilePic =\n partialConfig.profilePic ??\n partialConfig.profilePicUrl ??\n current?.profilePic ??\n \"\";\n\n window.ChatWidgetConfig = {\n title: partialConfig.title ?? current?.title ?? \"\",\n initialMessage: partialConfig.initialMessage ?? current?.initialMessage ?? \"\",\n profilePic: nextProfilePic,\n themeColor: partialConfig.themeColor ?? current?.themeColor ?? \"\",\n apiKey: partialConfig.apiKey ?? current?.apiKey ?? \"\",\n };\n}\n\nexport function destroyChatWidget(scriptId = currentScriptId) {\n if (!isBrowser()) return;\n\n const script = document.getElementById(scriptId);\n if (script) script.remove();\n\n delete window.ChatWidgetConfig;\n\n const widgetRoot = document.getElementById(\"chat-widget-root\");\n if (widgetRoot) widgetRoot.remove();\n}\n\nexport { DEFAULT_SCRIPT_ID, DEFAULT_SCRIPT_SRC };\n\nfunction normalizeConfig(config: ChatConfig): WindowChatWidgetConfig {\n return {\n title: config.title,\n initialMessage: config.initialMessage,\n profilePic: config.profilePic ?? config.profilePicUrl ?? \"\",\n themeColor: config.themeColor,\n apiKey: config.apiKey,\n };\n}\n","import { initChatWidget, updateChatWidgetConfig, destroyChatWidget } from \"../core\";\nimport type { ChatConfig, InitOptions } from \"../types\";\n\nexport function createNuxtChatWidgetPlugin(config: ChatConfig, options?: InitOptions) {\n return () => {\n initChatWidget(config, options);\n };\n}\n\nexport { initChatWidget, updateChatWidgetConfig, destroyChatWidget };\nexport type { ChatConfig, InitOptions };\n"]}
@@ -0,0 +1,6 @@
1
+ export { destroyChatWidget, initChatWidget, updateChatWidgetConfig } from '../index.cjs';
2
+ import { C as ChatConfig, I as InitOptions } from '../types-BWh0nkk_.cjs';
3
+
4
+ declare function createNuxtChatWidgetPlugin(config: ChatConfig, options?: InitOptions): () => void;
5
+
6
+ export { ChatConfig, InitOptions, createNuxtChatWidgetPlugin };
@@ -0,0 +1,6 @@
1
+ export { destroyChatWidget, initChatWidget, updateChatWidgetConfig } from '../index.js';
2
+ import { C as ChatConfig, I as InitOptions } from '../types-BWh0nkk_.js';
3
+
4
+ declare function createNuxtChatWidgetPlugin(config: ChatConfig, options?: InitOptions): () => void;
5
+
6
+ export { ChatConfig, InitOptions, createNuxtChatWidgetPlugin };
@@ -0,0 +1,13 @@
1
+ import { initChatWidget } from '../chunk-TJT546IL.js';
2
+ export { destroyChatWidget, initChatWidget, updateChatWidgetConfig } from '../chunk-TJT546IL.js';
3
+
4
+ // src/adapters/nuxt.ts
5
+ function createNuxtChatWidgetPlugin(config, options) {
6
+ return () => {
7
+ initChatWidget(config, options);
8
+ };
9
+ }
10
+
11
+ export { createNuxtChatWidgetPlugin };
12
+ //# sourceMappingURL=nuxt.js.map
13
+ //# sourceMappingURL=nuxt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/adapters/nuxt.ts"],"names":[],"mappings":";;;;AAGO,SAAS,0BAAA,CAA2B,QAAoB,OAAA,EAAuB;AACpF,EAAA,OAAO,MAAM;AACX,IAAA,cAAA,CAAe,QAAQ,OAAO,CAAA;AAAA,EAChC,CAAA;AACF","file":"nuxt.js","sourcesContent":["import { initChatWidget, updateChatWidgetConfig, destroyChatWidget } from \"../core\";\nimport type { ChatConfig, InitOptions } from \"../types\";\n\nexport function createNuxtChatWidgetPlugin(config: ChatConfig, options?: InitOptions) {\n return () => {\n initChatWidget(config, options);\n };\n}\n\nexport { initChatWidget, updateChatWidgetConfig, destroyChatWidget };\nexport type { ChatConfig, InitOptions };\n"]}
@@ -0,0 +1,95 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+
5
+ // src/adapters/react.ts
6
+
7
+ // src/core.ts
8
+ var DEFAULT_SCRIPT_ID = "chat-widget-script";
9
+ var DEFAULT_SCRIPT_SRC = "https://chatbot.avya.lk/chatbot-assistant";
10
+ var currentScriptId = DEFAULT_SCRIPT_ID;
11
+ function isBrowser() {
12
+ return typeof window !== "undefined" && typeof document !== "undefined";
13
+ }
14
+ function upsertScript(scriptSrc, scriptId, forceReload = false) {
15
+ const existing = document.getElementById(scriptId);
16
+ if (existing && !forceReload) {
17
+ return existing;
18
+ }
19
+ if (existing && forceReload) {
20
+ existing.remove();
21
+ }
22
+ const script = document.createElement("script");
23
+ script.id = scriptId;
24
+ script.src = scriptSrc;
25
+ script.async = true;
26
+ document.body.appendChild(script);
27
+ return script;
28
+ }
29
+ function initChatWidget(config, options = {}) {
30
+ if (!isBrowser()) return null;
31
+ const scriptSrc = options.scriptSrc ?? DEFAULT_SCRIPT_SRC;
32
+ const scriptId = options.scriptId ?? DEFAULT_SCRIPT_ID;
33
+ currentScriptId = scriptId;
34
+ window.ChatWidgetConfig = normalizeConfig(config);
35
+ return upsertScript(scriptSrc, scriptId, options.forceReload ?? false);
36
+ }
37
+ function updateChatWidgetConfig(partialConfig) {
38
+ if (!isBrowser()) return;
39
+ const current = window.ChatWidgetConfig;
40
+ const nextProfilePic = partialConfig.profilePic ?? partialConfig.profilePicUrl ?? current?.profilePic ?? "";
41
+ window.ChatWidgetConfig = {
42
+ title: partialConfig.title ?? current?.title ?? "",
43
+ initialMessage: partialConfig.initialMessage ?? current?.initialMessage ?? "",
44
+ profilePic: nextProfilePic,
45
+ themeColor: partialConfig.themeColor ?? current?.themeColor ?? "",
46
+ apiKey: partialConfig.apiKey ?? current?.apiKey ?? ""
47
+ };
48
+ }
49
+ function destroyChatWidget(scriptId = currentScriptId) {
50
+ if (!isBrowser()) return;
51
+ const script = document.getElementById(scriptId);
52
+ if (script) script.remove();
53
+ delete window.ChatWidgetConfig;
54
+ const widgetRoot = document.getElementById("chat-widget-root");
55
+ if (widgetRoot) widgetRoot.remove();
56
+ }
57
+ function normalizeConfig(config) {
58
+ return {
59
+ title: config.title,
60
+ initialMessage: config.initialMessage,
61
+ profilePic: config.profilePic ?? config.profilePicUrl ?? "",
62
+ themeColor: config.themeColor,
63
+ apiKey: config.apiKey
64
+ };
65
+ }
66
+
67
+ // src/adapters/react.ts
68
+ function useChatWidget(config, options) {
69
+ react.useEffect(() => {
70
+ initChatWidget(config, options);
71
+ }, []);
72
+ react.useEffect(() => {
73
+ updateChatWidgetConfig(config);
74
+ }, [config.title, config.initialMessage, config.profilePic, config.profilePicUrl, config.themeColor, config.apiKey]);
75
+ }
76
+ function ChatWidgetLoader({
77
+ config,
78
+ options,
79
+ cleanupOnUnmount = false
80
+ }) {
81
+ useChatWidget(config, options);
82
+ react.useEffect(() => {
83
+ return () => {
84
+ if (cleanupOnUnmount) {
85
+ destroyChatWidget(options?.scriptId);
86
+ }
87
+ };
88
+ }, [cleanupOnUnmount, options?.scriptId]);
89
+ return null;
90
+ }
91
+
92
+ exports.ChatWidgetLoader = ChatWidgetLoader;
93
+ exports.useChatWidget = useChatWidget;
94
+ //# sourceMappingURL=react.cjs.map
95
+ //# sourceMappingURL=react.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core.ts","../../src/adapters/react.ts"],"names":["useEffect"],"mappings":";;;;;;;AAEA,IAAM,iBAAA,GAAoB,oBAAA;AAC1B,IAAM,kBAAA,GAAqB,2CAAA;AAE3B,IAAI,eAAA,GAAkB,iBAAA;AAEtB,SAAS,SAAA,GAAY;AACnB,EAAA,OAAO,OAAO,MAAA,KAAW,WAAA,IAAe,OAAO,QAAA,KAAa,WAAA;AAC9D;AAEA,SAAS,YAAA,CAAa,SAAA,E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,EAAG,CAAC,MAAA,CAAO,KAAA,EAAO,OAAO,cAAA,EAAgB,MAAA,CAAO,UAAA,EAAY,MAAA,CAAO,aAAA,EAAe,MAAA,CAAO,UAAA,EAAY,MAAA,CAAO,MAAM,CAAC,CAAA;AACrH;AAEO,SAAS,gBAAA,CAAiB;AAAA,EAC/B,MAAA;AAAA,EACA,OAAA;AAAA,EACA,gBAAA,GAAmB;AACrB,CAAA,EAIG;AACD,EAAA,aAAA,CAAc,QAAQ,OAAO,CAAA;AAE7B,EAAAA,eAAA,CAAU,MAAM;AACd,IAAA,OAAO,MAAM;AACX,MAAA,IAAI,gBAAA,EAAkB;AACpB,QAAA,iBAAA,CAAkB,SAAS,QAAQ,CAAA;AAAA,MACrC;AAAA,IACF,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,gBAAA,EAAkB,OAAA,EAAS,QAAQ,CAAC,CAAA;AAExC,EAAA,OAAO,IAAA;AACT","file":"react.cjs","sourcesContent":["import type { ChatConfig, InitOptions, WindowChatWidgetConfig } from \"./types\";\n\nconst DEFAULT_SCRIPT_ID = \"chat-widget-script\";\nconst DEFAULT_SCRIPT_SRC = \"https://chatbot.avya.lk/chatbot-assistant\";\n\nlet currentScriptId = DEFAULT_SCRIPT_ID;\n\nfunction isBrowser() {\n return typeof window !== \"undefined\" && typeof document !== \"undefined\";\n}\n\nfunction upsertScript(scriptSrc: string, scriptId: string, forceReload = false) {\n const existing = document.getElementById(scriptId) as HTMLScriptElement | null;\n\n if (existing && !forceReload) {\n return existing;\n }\n\n if (existing && forceReload) {\n existing.remove();\n }\n\n const script = document.createElement(\"script\");\n script.id = scriptId;\n script.src = scriptSrc;\n script.async = true;\n document.body.appendChild(script);\n\n return script;\n}\n\nexport function initChatWidget(config: ChatConfig, options: InitOptions = {}) {\n if (!isBrowser()) return null;\n\n const scriptSrc = options.scriptSrc ?? DEFAULT_SCRIPT_SRC;\n const scriptId = options.scriptId ?? DEFAULT_SCRIPT_ID;\n currentScriptId = scriptId;\n\n window.ChatWidgetConfig = normalizeConfig(config);\n\n return upsertScript(scriptSrc, scriptId, options.forceReload ?? false);\n}\n\nexport function updateChatWidgetConfig(partialConfig: Partial<ChatConfig>) {\n if (!isBrowser()) return;\n\n const current = window.ChatWidgetConfig;\n const nextProfilePic =\n partialConfig.profilePic ??\n partialConfig.profilePicUrl ??\n current?.profilePic ??\n \"\";\n\n window.ChatWidgetConfig = {\n title: partialConfig.title ?? current?.title ?? \"\",\n initialMessage: partialConfig.initialMessage ?? current?.initialMessage ?? \"\",\n profilePic: nextProfilePic,\n themeColor: partialConfig.themeColor ?? current?.themeColor ?? \"\",\n apiKey: partialConfig.apiKey ?? current?.apiKey ?? \"\",\n };\n}\n\nexport function destroyChatWidget(scriptId = currentScriptId) {\n if (!isBrowser()) return;\n\n const script = document.getElementById(scriptId);\n if (script) script.remove();\n\n delete window.ChatWidgetConfig;\n\n const widgetRoot = document.getElementById(\"chat-widget-root\");\n if (widgetRoot) widgetRoot.remove();\n}\n\nexport { DEFAULT_SCRIPT_ID, DEFAULT_SCRIPT_SRC };\n\nfunction normalizeConfig(config: ChatConfig): WindowChatWidgetConfig {\n return {\n title: config.title,\n initialMessage: config.initialMessage,\n profilePic: config.profilePic ?? config.profilePicUrl ?? \"\",\n themeColor: config.themeColor,\n apiKey: config.apiKey,\n };\n}\n","import { useEffect } from \"react\";\nimport { initChatWidget, updateChatWidgetConfig, destroyChatWidget } from \"../core\";\nimport type { ChatConfig, InitOptions } from \"../types\";\n\nexport function useChatWidget(config: ChatConfig, options?: InitOptions) {\n useEffect(() => {\n initChatWidget(config, options);\n }, []);\n\n useEffect(() => {\n updateChatWidgetConfig(config);\n }, [config.title, config.initialMessage, config.profilePic, config.profilePicUrl, config.themeColor, config.apiKey]);\n}\n\nexport function ChatWidgetLoader({\n config,\n options,\n cleanupOnUnmount = false,\n}: {\n config: ChatConfig;\n options?: InitOptions;\n cleanupOnUnmount?: boolean;\n}) {\n useChatWidget(config, options);\n\n useEffect(() => {\n return () => {\n if (cleanupOnUnmount) {\n destroyChatWidget(options?.scriptId);\n }\n };\n }, [cleanupOnUnmount, options?.scriptId]);\n\n return null;\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { C as ChatConfig, I as InitOptions } from '../types-BWh0nkk_.cjs';
2
+
3
+ declare function useChatWidget(config: ChatConfig, options?: InitOptions): void;
4
+ declare function ChatWidgetLoader({ config, options, cleanupOnUnmount, }: {
5
+ config: ChatConfig;
6
+ options?: InitOptions;
7
+ cleanupOnUnmount?: boolean;
8
+ }): null;
9
+
10
+ export { ChatWidgetLoader, useChatWidget };
@@ -0,0 +1,10 @@
1
+ import { C as ChatConfig, I as InitOptions } from '../types-BWh0nkk_.js';
2
+
3
+ declare function useChatWidget(config: ChatConfig, options?: InitOptions): void;
4
+ declare function ChatWidgetLoader({ config, options, cleanupOnUnmount, }: {
5
+ config: ChatConfig;
6
+ options?: InitOptions;
7
+ cleanupOnUnmount?: boolean;
8
+ }): null;
9
+
10
+ export { ChatWidgetLoader, useChatWidget };
@@ -0,0 +1,30 @@
1
+ import { initChatWidget, updateChatWidgetConfig, destroyChatWidget } from '../chunk-TJT546IL.js';
2
+ import { useEffect } from 'react';
3
+
4
+ function useChatWidget(config, options) {
5
+ useEffect(() => {
6
+ initChatWidget(config, options);
7
+ }, []);
8
+ useEffect(() => {
9
+ updateChatWidgetConfig(config);
10
+ }, [config.title, config.initialMessage, config.profilePic, config.profilePicUrl, config.themeColor, config.apiKey]);
11
+ }
12
+ function ChatWidgetLoader({
13
+ config,
14
+ options,
15
+ cleanupOnUnmount = false
16
+ }) {
17
+ useChatWidget(config, options);
18
+ useEffect(() => {
19
+ return () => {
20
+ if (cleanupOnUnmount) {
21
+ destroyChatWidget(options?.scriptId);
22
+ }
23
+ };
24
+ }, [cleanupOnUnmount, options?.scriptId]);
25
+ return null;
26
+ }
27
+
28
+ export { ChatWidgetLoader, useChatWidget };
29
+ //# sourceMappingURL=react.js.map
30
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/adapters/react.ts"],"names":[],"mappings":";;;AAIO,SAAS,aAAA,CAAc,QAAoB,OAAA,EAAuB;AACvE,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,cAAA,CAAe,QAAQ,OAAO,CAAA;AAAA,EAChC,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,sBAAA,CAAuB,MAAM,CAAA;AAAA,EAC/B,CAAA,EAAG,CAAC,MAAA,CAAO,KAAA,EAAO,OAAO,cAAA,EAAgB,MAAA,CAAO,UAAA,EAAY,MAAA,CAAO,aAAA,EAAe,MAAA,CAAO,UAAA,EAAY,MAAA,CAAO,MAAM,CAAC,CAAA;AACrH;AAEO,SAAS,gBAAA,CAAiB;AAAA,EAC/B,MAAA;AAAA,EACA,OAAA;AAAA,EACA,gBAAA,GAAmB;AACrB,CAAA,EAIG;AACD,EAAA,aAAA,CAAc,QAAQ,OAAO,CAAA;AAE7B,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,OAAO,MAAM;AACX,MAAA,IAAI,gBAAA,EAAkB;AACpB,QAAA,iBAAA,CAAkB,SAAS,QAAQ,CAAA;AAAA,MACrC;AAAA,IACF,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,gBAAA,EAAkB,OAAA,EAAS,QAAQ,CAAC,CAAA;AAExC,EAAA,OAAO,IAAA;AACT","file":"react.js","sourcesContent":["import { useEffect } from \"react\";\nimport { initChatWidget, updateChatWidgetConfig, destroyChatWidget } from \"../core\";\nimport type { ChatConfig, InitOptions } from \"../types\";\n\nexport function useChatWidget(config: ChatConfig, options?: InitOptions) {\n useEffect(() => {\n initChatWidget(config, options);\n }, []);\n\n useEffect(() => {\n updateChatWidgetConfig(config);\n }, [config.title, config.initialMessage, config.profilePic, config.profilePicUrl, config.themeColor, config.apiKey]);\n}\n\nexport function ChatWidgetLoader({\n config,\n options,\n cleanupOnUnmount = false,\n}: {\n config: ChatConfig;\n options?: InitOptions;\n cleanupOnUnmount?: boolean;\n}) {\n useChatWidget(config, options);\n\n useEffect(() => {\n return () => {\n if (cleanupOnUnmount) {\n destroyChatWidget(options?.scriptId);\n }\n };\n }, [cleanupOnUnmount, options?.scriptId]);\n\n return null;\n}\n"]}
@@ -0,0 +1,63 @@
1
+ // src/core.ts
2
+ var DEFAULT_SCRIPT_ID = "chat-widget-script";
3
+ var DEFAULT_SCRIPT_SRC = "https://chatbot.avya.lk/chatbot-assistant";
4
+ var currentScriptId = DEFAULT_SCRIPT_ID;
5
+ function isBrowser() {
6
+ return typeof window !== "undefined" && typeof document !== "undefined";
7
+ }
8
+ function upsertScript(scriptSrc, scriptId, forceReload = false) {
9
+ const existing = document.getElementById(scriptId);
10
+ if (existing && !forceReload) {
11
+ return existing;
12
+ }
13
+ if (existing && forceReload) {
14
+ existing.remove();
15
+ }
16
+ const script = document.createElement("script");
17
+ script.id = scriptId;
18
+ script.src = scriptSrc;
19
+ script.async = true;
20
+ document.body.appendChild(script);
21
+ return script;
22
+ }
23
+ function initChatWidget(config, options = {}) {
24
+ if (!isBrowser()) return null;
25
+ const scriptSrc = options.scriptSrc ?? DEFAULT_SCRIPT_SRC;
26
+ const scriptId = options.scriptId ?? DEFAULT_SCRIPT_ID;
27
+ currentScriptId = scriptId;
28
+ window.ChatWidgetConfig = normalizeConfig(config);
29
+ return upsertScript(scriptSrc, scriptId, options.forceReload ?? false);
30
+ }
31
+ function updateChatWidgetConfig(partialConfig) {
32
+ if (!isBrowser()) return;
33
+ const current = window.ChatWidgetConfig;
34
+ const nextProfilePic = partialConfig.profilePic ?? partialConfig.profilePicUrl ?? current?.profilePic ?? "";
35
+ window.ChatWidgetConfig = {
36
+ title: partialConfig.title ?? current?.title ?? "",
37
+ initialMessage: partialConfig.initialMessage ?? current?.initialMessage ?? "",
38
+ profilePic: nextProfilePic,
39
+ themeColor: partialConfig.themeColor ?? current?.themeColor ?? "",
40
+ apiKey: partialConfig.apiKey ?? current?.apiKey ?? ""
41
+ };
42
+ }
43
+ function destroyChatWidget(scriptId = currentScriptId) {
44
+ if (!isBrowser()) return;
45
+ const script = document.getElementById(scriptId);
46
+ if (script) script.remove();
47
+ delete window.ChatWidgetConfig;
48
+ const widgetRoot = document.getElementById("chat-widget-root");
49
+ if (widgetRoot) widgetRoot.remove();
50
+ }
51
+ function normalizeConfig(config) {
52
+ return {
53
+ title: config.title,
54
+ initialMessage: config.initialMessage,
55
+ profilePic: config.profilePic ?? config.profilePicUrl ?? "",
56
+ themeColor: config.themeColor,
57
+ apiKey: config.apiKey
58
+ };
59
+ }
60
+
61
+ export { DEFAULT_SCRIPT_ID, DEFAULT_SCRIPT_SRC, destroyChatWidget, initChatWidget, updateChatWidgetConfig };
62
+ //# sourceMappingURL=chunk-TJT546IL.js.map
63
+ //# sourceMappingURL=chunk-TJT546IL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core.ts"],"names":[],"mappings":";AAEA,IAAM,iBAAA,GAAoB;AAC1B,IAAM,kBAAA,GAAqB;AAE3B,IAAI,eAAA,GAAkB,iBAAA;AAEtB,SAAS,SAAA,GAAY;AACnB,EAAA,OAAO,OAAO,MAAA,KAAW,WAAA,IAAe,OAAO,QAAA,KAAa,WAAA;AAC9D;AAEA,SAAS,YAAA,CAAa,SAAA,EAAmB,QAAA,EAAkB,WAAA,GAAc,KAAA,EAAO;AAC9E,EAAA,MAAM,QAAA,GAAW,QAAA,CAAS,cAAA,CAAe,QAAQ,CAAA;AAEjD,EAAA,IAAI,QAAA,IAAY,CAAC,WAAA,EAAa;AAC5B,IAAA,OAAO,QAAA;AAAA,EACT;AAEA,EAAA,IAAI,YAAY,WAAA,EAAa;AAC3B,IAAA,QAAA,CAAS,MAAA,EAAO;AAAA,EAClB;AAEA,EAAA,MAAM,MAAA,GAAS,QAAA,CAAS,aAAA,CAAc,QAAQ,CAAA;AAC9C,EAAA,MAAA,CAAO,EAAA,GAAK,QAAA;AACZ,EAAA,MAAA,CAAO,GA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,WAAU,EAAG;AAElB,EAAA,MAAM,MAAA,GAAS,QAAA,CAAS,cAAA,CAAe,QAAQ,CAAA;AAC/C,EAAA,IAAI,MAAA,SAAe,MAAA,EAAO;AAE1B,EAAA,OAAO,MAAA,CAAO,gBAAA;AAEd,EAAA,MAAM,UAAA,GAAa,QAAA,CAAS,cAAA,CAAe,kBAAkB,CAAA;AAC7D,EAAA,IAAI,UAAA,aAAuB,MAAA,EAAO;AACpC;AAIA,SAAS,gBAAgB,MAAA,EAA4C;AACnE,EAAA,OAAO;AAAA,IACL,OAAO,MAAA,CAAO,KAAA;AAAA,IACd,gBAAgB,MAAA,CAAO,cAAA;AAAA,IACvB,UAAA,EAAY,MAAA,CAAO,UAAA,IAAc,MAAA,CAAO,aAAA,IAAiB,EAAA;AAAA,IACzD,YAAY,MAAA,CAAO,UAAA;AAAA,IACnB,QAAQ,MAAA,CAAO;AAAA,GACjB;AACF","file":"chunk-TJT546IL.js","sourcesContent":["import type { ChatConfig, InitOptions, WindowChatWidgetConfig } from \"./types\";\n\nconst DEFAULT_SCRIPT_ID = \"chat-widget-script\";\nconst DEFAULT_SCRIPT_SRC = \"https://chatbot.avya.lk/chatbot-assistant\";\n\nlet currentScriptId = DEFAULT_SCRIPT_ID;\n\nfunction isBrowser() {\n return typeof window !== \"undefined\" && typeof document !== \"undefined\";\n}\n\nfunction upsertScript(scriptSrc: string, scriptId: string, forceReload = false) {\n const existing = document.getElementById(scriptId) as HTMLScriptElement | null;\n\n if (existing && !forceReload) {\n return existing;\n }\n\n if (existing && forceReload) {\n existing.remove();\n }\n\n const script = document.createElement(\"script\");\n script.id = scriptId;\n script.src = scriptSrc;\n script.async = true;\n document.body.appendChild(script);\n\n return script;\n}\n\nexport function initChatWidget(config: ChatConfig, options: InitOptions = {}) {\n if (!isBrowser()) return null;\n\n const scriptSrc = options.scriptSrc ?? DEFAULT_SCRIPT_SRC;\n const scriptId = options.scriptId ?? DEFAULT_SCRIPT_ID;\n currentScriptId = scriptId;\n\n window.ChatWidgetConfig = normalizeConfig(config);\n\n return upsertScript(scriptSrc, scriptId, options.forceReload ?? false);\n}\n\nexport function updateChatWidgetConfig(partialConfig: Partial<ChatConfig>) {\n if (!isBrowser()) return;\n\n const current = window.ChatWidgetConfig;\n const nextProfilePic =\n partialConfig.profilePic ??\n partialConfig.profilePicUrl ??\n current?.profilePic ??\n \"\";\n\n window.ChatWidgetConfig = {\n title: partialConfig.title ?? current?.title ?? \"\",\n initialMessage: partialConfig.initialMessage ?? current?.initialMessage ?? \"\",\n profilePic: nextProfilePic,\n themeColor: partialConfig.themeColor ?? current?.themeColor ?? \"\",\n apiKey: partialConfig.apiKey ?? current?.apiKey ?? \"\",\n };\n}\n\nexport function destroyChatWidget(scriptId = currentScriptId) {\n if (!isBrowser()) return;\n\n const script = document.getElementById(scriptId);\n if (script) script.remove();\n\n delete window.ChatWidgetConfig;\n\n const widgetRoot = document.getElementById(\"chat-widget-root\");\n if (widgetRoot) widgetRoot.remove();\n}\n\nexport { DEFAULT_SCRIPT_ID, DEFAULT_SCRIPT_SRC };\n\nfunction normalizeConfig(config: ChatConfig): WindowChatWidgetConfig {\n return {\n title: config.title,\n initialMessage: config.initialMessage,\n profilePic: config.profilePic ?? config.profilePicUrl ?? \"\",\n themeColor: config.themeColor,\n apiKey: config.apiKey,\n };\n}\n"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ // src/core.ts
4
+ var DEFAULT_SCRIPT_ID = "chat-widget-script";
5
+ var DEFAULT_SCRIPT_SRC = "https://chatbot.avya.lk/chatbot-assistant";
6
+ var currentScriptId = DEFAULT_SCRIPT_ID;
7
+ function isBrowser() {
8
+ return typeof window !== "undefined" && typeof document !== "undefined";
9
+ }
10
+ function upsertScript(scriptSrc, scriptId, forceReload = false) {
11
+ const existing = document.getElementById(scriptId);
12
+ if (existing && !forceReload) {
13
+ return existing;
14
+ }
15
+ if (existing && forceReload) {
16
+ existing.remove();
17
+ }
18
+ const script = document.createElement("script");
19
+ script.id = scriptId;
20
+ script.src = scriptSrc;
21
+ script.async = true;
22
+ document.body.appendChild(script);
23
+ return script;
24
+ }
25
+ function initChatWidget(config, options = {}) {
26
+ if (!isBrowser()) return null;
27
+ const scriptSrc = options.scriptSrc ?? DEFAULT_SCRIPT_SRC;
28
+ const scriptId = options.scriptId ?? DEFAULT_SCRIPT_ID;
29
+ currentScriptId = scriptId;
30
+ window.ChatWidgetConfig = normalizeConfig(config);
31
+ return upsertScript(scriptSrc, scriptId, options.forceReload ?? false);
32
+ }
33
+ function updateChatWidgetConfig(partialConfig) {
34
+ if (!isBrowser()) return;
35
+ const current = window.ChatWidgetConfig;
36
+ const nextProfilePic = partialConfig.profilePic ?? partialConfig.profilePicUrl ?? current?.profilePic ?? "";
37
+ window.ChatWidgetConfig = {
38
+ title: partialConfig.title ?? current?.title ?? "",
39
+ initialMessage: partialConfig.initialMessage ?? current?.initialMessage ?? "",
40
+ profilePic: nextProfilePic,
41
+ themeColor: partialConfig.themeColor ?? current?.themeColor ?? "",
42
+ apiKey: partialConfig.apiKey ?? current?.apiKey ?? ""
43
+ };
44
+ }
45
+ function destroyChatWidget(scriptId = currentScriptId) {
46
+ if (!isBrowser()) return;
47
+ const script = document.getElementById(scriptId);
48
+ if (script) script.remove();
49
+ delete window.ChatWidgetConfig;
50
+ const widgetRoot = document.getElementById("chat-widget-root");
51
+ if (widgetRoot) widgetRoot.remove();
52
+ }
53
+ function normalizeConfig(config) {
54
+ return {
55
+ title: config.title,
56
+ initialMessage: config.initialMessage,
57
+ profilePic: config.profilePic ?? config.profilePicUrl ?? "",
58
+ themeColor: config.themeColor,
59
+ apiKey: config.apiKey
60
+ };
61
+ }
62
+
63
+ exports.DEFAULT_SCRIPT_ID = DEFAULT_SCRIPT_ID;
64
+ exports.DEFAULT_SCRIPT_SRC = DEFAULT_SCRIPT_SRC;
65
+ exports.destroyChatWidget = destroyChatWidget;
66
+ exports.initChatWidget = initChatWidget;
67
+ exports.update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AA,IAAc,MAAA,CAAO,aAAA,IAAiB,EAAA;AAAA,IACzD,YAAY,MAAA,CAAO,UAAA;AAAA,IACnB,QAAQ,MAAA,CAAO;AAAA,GACjB;AACF","file":"index.cjs","sourcesContent":["import type { ChatConfig, InitOptions, WindowChatWidgetConfig } from \"./types\";\n\nconst DEFAULT_SCRIPT_ID = \"chat-widget-script\";\nconst DEFAULT_SCRIPT_SRC = \"https://chatbot.avya.lk/chatbot-assistant\";\n\nlet currentScriptId = DEFAULT_SCRIPT_ID;\n\nfunction isBrowser() {\n return typeof window !== \"undefined\" && typeof document !== \"undefined\";\n}\n\nfunction upsertScript(scriptSrc: string, scriptId: string, forceReload = false) {\n const existing = document.getElementById(scriptId) as HTMLScriptElement | null;\n\n if (existing && !forceReload) {\n return existing;\n }\n\n if (existing && forceReload) {\n existing.remove();\n }\n\n const script = document.createElement(\"script\");\n script.id = scriptId;\n script.src = scriptSrc;\n script.async = true;\n document.body.appendChild(script);\n\n return script;\n}\n\nexport function initChatWidget(config: ChatConfig, options: InitOptions = {}) {\n if (!isBrowser()) return null;\n\n const scriptSrc = options.scriptSrc ?? DEFAULT_SCRIPT_SRC;\n const scriptId = options.scriptId ?? DEFAULT_SCRIPT_ID;\n currentScriptId = scriptId;\n\n window.ChatWidgetConfig = normalizeConfig(config);\n\n return upsertScript(scriptSrc, scriptId, options.forceReload ?? false);\n}\n\nexport function updateChatWidgetConfig(partialConfig: Partial<ChatConfig>) {\n if (!isBrowser()) return;\n\n const current = window.ChatWidgetConfig;\n const nextProfilePic =\n partialConfig.profilePic ??\n partialConfig.profilePicUrl ??\n current?.profilePic ??\n \"\";\n\n window.ChatWidgetConfig = {\n title: partialConfig.title ?? current?.title ?? \"\",\n initialMessage: partialConfig.initialMessage ?? current?.initialMessage ?? \"\",\n profilePic: nextProfilePic,\n themeColor: partialConfig.themeColor ?? current?.themeColor ?? \"\",\n apiKey: partialConfig.apiKey ?? current?.apiKey ?? \"\",\n };\n}\n\nexport function destroyChatWidget(scriptId = currentScriptId) {\n if (!isBrowser()) return;\n\n const script = document.getElementById(scriptId);\n if (script) script.remove();\n\n delete window.ChatWidgetConfig;\n\n const widgetRoot = document.getElementById(\"chat-widget-root\");\n if (widgetRoot) widgetRoot.remove();\n}\n\nexport { DEFAULT_SCRIPT_ID, DEFAULT_SCRIPT_SRC };\n\nfunction normalizeConfig(config: ChatConfig): WindowChatWidgetConfig {\n return {\n title: config.title,\n initialMessage: config.initialMessage,\n profilePic: config.profilePic ?? config.profilePicUrl ?? \"\",\n themeColor: config.themeColor,\n apiKey: config.apiKey,\n };\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import { C as ChatConfig, I as InitOptions } from './types-BWh0nkk_.cjs';
2
+
3
+ declare const DEFAULT_SCRIPT_ID = "chat-widget-script";
4
+ declare const DEFAULT_SCRIPT_SRC = "https://chatbot.avya.lk/chatbot-assistant";
5
+ declare function initChatWidget(config: ChatConfig, options?: InitOptions): HTMLScriptElement | null;
6
+ declare function updateChatWidgetConfig(partialConfig: Partial<ChatConfig>): void;
7
+ declare function destroyChatWidget(scriptId?: string): void;
8
+
9
+ export { ChatConfig, DEFAULT_SCRIPT_ID, DEFAULT_SCRIPT_SRC, InitOptions, destroyChatWidget, initChatWidget, updateChatWidgetConfig };
@@ -0,0 +1,9 @@
1
+ import { C as ChatConfig, I as InitOptions } from './types-BWh0nkk_.js';
2
+
3
+ declare const DEFAULT_SCRIPT_ID = "chat-widget-script";
4
+ declare const DEFAULT_SCRIPT_SRC = "https://chatbot.avya.lk/chatbot-assistant";
5
+ declare function initChatWidget(config: ChatConfig, options?: InitOptions): HTMLScriptElement | null;
6
+ declare function updateChatWidgetConfig(partialConfig: Partial<ChatConfig>): void;
7
+ declare function destroyChatWidget(scriptId?: string): void;
8
+
9
+ export { ChatConfig, DEFAULT_SCRIPT_ID, DEFAULT_SCRIPT_SRC, InitOptions, destroyChatWidget, initChatWidget, updateChatWidgetConfig };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { DEFAULT_SCRIPT_ID, DEFAULT_SCRIPT_SRC, destroyChatWidget, initChatWidget, updateChatWidgetConfig } from './chunk-TJT546IL.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,27 @@
1
+ interface ChatConfig {
2
+ title: string;
3
+ initialMessage: string;
4
+ profilePicUrl?: string;
5
+ profilePic?: string;
6
+ themeColor: string;
7
+ apiKey: string;
8
+ }
9
+ interface WindowChatWidgetConfig {
10
+ title: string;
11
+ initialMessage: string;
12
+ profilePic: string;
13
+ themeColor: string;
14
+ apiKey: string;
15
+ }
16
+ interface InitOptions {
17
+ scriptSrc?: string;
18
+ scriptId?: string;
19
+ forceReload?: boolean;
20
+ }
21
+ declare global {
22
+ interface Window {
23
+ ChatWidgetConfig?: WindowChatWidgetConfig;
24
+ }
25
+ }
26
+
27
+ export type { ChatConfig as C, InitOptions as I };
@@ -0,0 +1,27 @@
1
+ interface ChatConfig {
2
+ title: string;
3
+ initialMessage: string;
4
+ profilePicUrl?: string;
5
+ profilePic?: string;
6
+ themeColor: string;
7
+ apiKey: string;
8
+ }
9
+ interface WindowChatWidgetConfig {
10
+ title: string;
11
+ initialMessage: string;
12
+ profilePic: string;
13
+ themeColor: string;
14
+ apiKey: string;
15
+ }
16
+ interface InitOptions {
17
+ scriptSrc?: string;
18
+ scriptId?: string;
19
+ forceReload?: boolean;
20
+ }
21
+ declare global {
22
+ interface Window {
23
+ ChatWidgetConfig?: WindowChatWidgetConfig;
24
+ }
25
+ }
26
+
27
+ export type { ChatConfig as C, InitOptions as I };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "chatbot-web-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Web SDK for Avya chatbot widget (React, Next.js, Nuxt, and plain JS).",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs"
15
+ },
16
+ "./react": {
17
+ "types": "./dist/adapters/react.d.ts",
18
+ "import": "./dist/adapters/react.js",
19
+ "require": "./dist/adapters/react.cjs"
20
+ },
21
+ "./nuxt": {
22
+ "types": "./dist/adapters/nuxt.d.ts",
23
+ "import": "./dist/adapters/nuxt.js",
24
+ "require": "./dist/adapters/nuxt.cjs"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "README.md",
30
+ "LICENSE"
31
+ ],
32
+ "sideEffects": false,
33
+ "scripts": {
34
+ "clean": "rimraf dist",
35
+ "build": "npm run clean && tsup",
36
+ "typecheck": "tsc --noEmit"
37
+ },
38
+ "peerDependencies": {
39
+ "react": ">=18"
40
+ },
41
+ "peerDependenciesMeta": {
42
+ "react": {
43
+ "optional": true
44
+ }
45
+ },
46
+ "devDependencies": {
47
+ "@types/react": "^19.2.14",
48
+ "rimraf": "^6.0.1",
49
+ "tsup": "^8.5.0",
50
+ "typescript": "^5.9.3"
51
+ }
52
+ }