@bnagaraju7/chat-widget 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 bnagaraju7
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,223 @@
1
+ # @bnagaraju7/chat-widget
2
+
3
+ The GarudaVPN support chat widget — AI chatbot, voice call + OTP, and
4
+ browser speech-to-text input — packaged for reuse outside the main Next.js
5
+ app:
6
+
7
+ - as an **npm package** for other React apps
8
+ - as a **CDN `<script>` bundle** for any third-party website
9
+
10
+ Everything talks to your backend over plain REST (`apiBaseUrl`) — there is
11
+ no Supabase or any other direct database dependency in this package.
12
+
13
+ > Published under the `@bnagaraju7` npm scope. Forking this for your own org?
14
+ > Change `name` in `package.json` to your own scope (`@your-npm-username/chat-widget`)
15
+ > or an unscoped name (`garuda-chat-widget`) before running `npm publish`.
16
+
17
+ ## Scope
18
+
19
+ This package is intentionally smaller than the chat experience inside the
20
+ main app. It covers:
21
+
22
+ - AI chatbot (text chat via `POST {apiBaseUrl}/api/v1/agents/chat`)
23
+ - Voice call + OTP verification (via `{apiBaseUrl}/api/v1/call/*`, Twilio Voice SDK)
24
+ - Browser speech-to-text input (Web Speech API)
25
+ - End-of-chat resolution/rating flow (via `POST {apiBaseUrl}/api/v1/ratings/respond`)
26
+
27
+ It does **not** include session history, human-agent live handoff, or
28
+ edited-message display — those depended on the main app's direct
29
+ browser-to-Supabase access, which this package doesn't have. If you need
30
+ them here, your backend would need to expose REST endpoints for
31
+ sessions/messages/agent-routing/agent-messages (with polling in place of
32
+ Supabase Realtime).
33
+
34
+ ## Build
35
+
36
+ ```bash
37
+ cd chat
38
+ npm install
39
+ npm run build
40
+ ```
41
+
42
+ Produces:
43
+
44
+ - `dist/index.mjs`, `dist/index.cjs`, `dist/index.d.ts` — the npm package
45
+ - `dist/cdn/garuda-chat-widget.iife.global.js` — the CDN bundle (React/ReactDOM included)
46
+
47
+ ## Usage — CDN
48
+
49
+ ```html
50
+ <script
51
+ src="https://cdn.example.com/garuda-chat-widget.iife.global.js"
52
+ data-api-base-url="https://api.example.com"
53
+ data-organisation-id="your-org-id"
54
+ data-support-phone="+1 555 0100"
55
+ async
56
+ ></script>
57
+ ```
58
+
59
+ The script auto-mounts using the `data-*` attributes on its own `<script>`
60
+ tag. For full control (custom `user`, `authToken`, callbacks, or a dynamic
61
+ SPA re-init), call `init` yourself instead of relying on auto-mount:
62
+
63
+ ```html
64
+ <script src="https://cdn.example.com/garuda-chat-widget.iife.global.js"></script>
65
+ <script>
66
+ window.GarudaChat.init({
67
+ apiBaseUrl: "https://api.example.com",
68
+ organisationId: "your-org-id",
69
+ supportPhone: "+1 555 0100",
70
+ });
71
+ </script>
72
+ ```
73
+
74
+ ## Usage — npm
75
+
76
+ ```bash
77
+ npm install @bnagaraju7/chat-widget
78
+ ```
79
+
80
+ ```tsx
81
+ import { GarudaChatWidget } from "@bnagaraju7/chat-widget";
82
+
83
+ <GarudaChatWidget
84
+ config={{
85
+ apiBaseUrl: "https://api.example.com",
86
+ organisationId: "your-org-id",
87
+ supportPhone: "+1 555 0100",
88
+ }}
89
+ />;
90
+ ```
91
+
92
+ `react` and `react-dom` are peer dependencies (`>=18`), so consumer apps
93
+ don't end up with a duplicate React copy. The package ships a `"use client"`
94
+ banner, so it works as-is in a React Server Components tree too (see Next.js
95
+ below) — no extra client wrapper needed.
96
+
97
+ ## Usage — Next.js
98
+
99
+ Works with both the App Router and the Pages Router.
100
+
101
+ **App Router** — the component can be imported directly into a Server
102
+ Component; it renders itself on the client because the bundle already
103
+ carries `"use client"`:
104
+
105
+ ```tsx
106
+ // app/layout.tsx
107
+ import { GarudaChatWidget } from "@bnagaraju7/chat-widget";
108
+
109
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
110
+ return (
111
+ <html lang="en">
112
+ <body>
113
+ {children}
114
+ <GarudaChatWidget
115
+ config={{
116
+ apiBaseUrl: process.env.NEXT_PUBLIC_CHAT_API_BASE_URL!,
117
+ organisationId: process.env.NEXT_PUBLIC_CHAT_ORG_ID,
118
+ supportPhone: "+1 555 0100",
119
+ }}
120
+ />
121
+ </body>
122
+ </html>
123
+ );
124
+ }
125
+ ```
126
+
127
+ **Pages Router** — mount it once in `_app.tsx`:
128
+
129
+ ```tsx
130
+ // pages/_app.tsx
131
+ import type { AppProps } from "next/app";
132
+ import { GarudaChatWidget } from "@bnagaraju7/chat-widget";
133
+
134
+ export default function App({ Component, pageProps }: AppProps) {
135
+ return (
136
+ <>
137
+ <Component {...pageProps} />
138
+ <GarudaChatWidget
139
+ config={{ apiBaseUrl: process.env.NEXT_PUBLIC_CHAT_API_BASE_URL! }}
140
+ />
141
+ </>
142
+ );
143
+ }
144
+ ```
145
+
146
+ Use `NEXT_PUBLIC_*` env vars for any config value needed in the browser —
147
+ plain (non-`NEXT_PUBLIC_`) env vars aren't available client-side.
148
+
149
+ ## Usage — Odoo 19
150
+
151
+ Odoo isn't React-based, so integrate via the **CDN `<script>` bundle**
152
+ (self-contained, includes React) rather than the npm package.
153
+
154
+ Host `dist/cdn/garuda-chat-widget.iife.global.js` somewhere Odoo can reach it
155
+ (your own static hosting, or as a public asset in a custom module) and add
156
+ the `<script>` tag using one of:
157
+
158
+ - **Website Builder, no custom module** — *Website ‣ Configuration ‣
159
+ Settings ‣ SEO* section has a "Custom Code" / head-and-body-script field
160
+ (or *Website ‣ Site ‣ Settings ‣ Tracking Codes* on some builds) — paste
161
+ the snippet into the "Body" custom code box so it loads on every page:
162
+
163
+ ```html
164
+ <script
165
+ src="https://your-static-host.example.com/garuda-chat-widget.iife.global.js"
166
+ data-api-base-url="https://api.example.com"
167
+ data-organisation-id="your-org-id"
168
+ data-support-phone="+1 555 0100"
169
+ async
170
+ ></script>
171
+ ```
172
+
173
+ - **Custom module** — bundle the JS file under
174
+ `your_module/static/src/js/` and add it to the website's assets bundle in
175
+ `__manifest__.py`:
176
+
177
+ ```python
178
+ "assets": {
179
+ "web.assets_frontend": [
180
+ "your_module/static/src/js/garuda-chat-widget.iife.global.js",
181
+ ],
182
+ },
183
+ ```
184
+
185
+ then set the config once from a small QWeb-injected script (e.g. in a
186
+ `website.layout` inherited template) instead of `data-*` attributes:
187
+
188
+ ```xml
189
+ <xpath expr="//body" position="inside">
190
+ <script t-if="request.website">
191
+ window.GarudaChat &amp;&amp; window.GarudaChat.init({
192
+ apiBaseUrl: "https://api.example.com",
193
+ organisationId: "your-org-id",
194
+ });
195
+ </script>
196
+ </xpath>
197
+ ```
198
+
199
+ Either way, make sure the backend behind `apiBaseUrl` has CORS enabled for
200
+ your Odoo site's domain (see "Backend prerequisite" below).
201
+
202
+ ## Config reference
203
+
204
+ | Field | Required | Description |
205
+ | ---------------------------- | -------- | ----------------------------------------------------------------------------- |
206
+ | `apiBaseUrl` | yes | Base URL of the support/chat REST API. |
207
+ | `organisationId` | no | Sent as the `organisation_id` header on every REST request. |
208
+ | `supportPhone` | no | Phone number for the voice-call fallback. Omit to hide the call button. |
209
+ | `user` | no | `{ id, fullname?, email? }` — used for the welcome message and rating submission. |
210
+ | `authToken` | no | Bearer token for REST requests. Omit for guest (unauthenticated) mode. |
211
+ | `onNavigateToKnowledgeBase` | no | Called when a user clicks a knowledge-base article result. |
212
+ | `onUnauthorized` | no | Called on a 401 from an authenticated request. |
213
+
214
+ ## Backend prerequisite
215
+
216
+ The backend behind `apiBaseUrl` (chat, voice token, OTP, ratings endpoints)
217
+ needs CORS enabled for cross-origin requests from whatever domains will
218
+ embed the widget.
219
+
220
+ ## Example
221
+
222
+ `example/cdn-demo.html` loads the built IIFE bundle with placeholder config
223
+ for manual smoke-testing — see that file for how to serve it locally.