@flowengage/react-chatbot 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/README.md CHANGED
@@ -5,41 +5,178 @@ Add live chat, AI assistant, and agent handoff to any site in minutes. All you n
5
5
 
6
6
  ---
7
7
 
8
- ## Installation
8
+ ## Choose how to integrate
9
+
10
+ | Approach | Best for | What you add |
11
+ |----------|-----------|--------------|
12
+ | **npm package** | React, Next.js, Vite, Remix, etc. | Install the package, wrap your app with `FlowEngageProvider`, render `FlowEngageWidget`. |
13
+ | **CDN (script tag)** | Plain HTML, PHP, WordPress, Drupal, non-React SPAs | One `<script>` tag; styles are bundled into the embed — no separate CSS file. |
14
+
15
+ You need a **Site ID** from the [FlowEngage dashboard](https://app.flowengage.com) (Integration Guide or site settings).
16
+
17
+ ---
18
+
19
+ ## A. npm package (React / Next.js / Vite)
20
+
21
+ ### Prerequisites
22
+
23
+ - **React 18+** and **react-dom 18+** in your project (peer dependencies).
24
+ - Node 18+ recommended for local development.
25
+
26
+ ### 1. Install
9
27
 
10
28
  ```bash
11
29
  npm install @flowengage/react-chatbot
30
+ ```
31
+
32
+ ```bash
12
33
  # or
13
34
  yarn add @flowengage/react-chatbot
35
+ pnpm add @flowengage/react-chatbot
14
36
  ```
15
37
 
16
- > **Peer dependencies**: React 18+ and ReactDOM 18+ must already be installed in your project.
38
+ Pin a version in production if you prefer reproducible builds:
17
39
 
18
- ---
40
+ ```bash
41
+ npm install @flowengage/react-chatbot@^1.0.0
42
+ ```
43
+
44
+ ### 2. Import the stylesheet once
45
+
46
+ The widget ships its own CSS. Import it at your app entry (or a layout file):
47
+
48
+ ```js
49
+ import '@flowengage/react-chatbot/styles.css';
50
+ ```
19
51
 
20
- ## Quick Start — React / Next.js / Vite
52
+ ### 3. Wrap your app and mount the widget
21
53
 
22
- ### 1. Wrap your app with the provider
54
+ `FlowEngageProvider` must wrap any component that uses `FlowEngageWidget` or `useFlowEngage`.
23
55
 
24
56
  ```jsx
25
- // app.jsx (or _app.tsx in Next.js, main.jsx in Vite, etc.)
57
+ // e.g. App.jsx, main.jsx, or a root layout wrapper
26
58
  import { FlowEngageProvider, FlowEngageWidget } from '@flowengage/react-chatbot';
27
59
  import '@flowengage/react-chatbot/styles.css';
28
60
 
29
61
  export default function App() {
30
62
  return (
31
63
  <FlowEngageProvider siteId="YOUR_SITE_ID">
32
- {/* your existing app content */}
33
- <YourApp />
34
-
35
- {/* drop the widget anywhere inside the provider */}
64
+ <YourExistingApp />
36
65
  <FlowEngageWidget />
37
66
  </FlowEngageProvider>
38
67
  );
39
68
  }
40
69
  ```
41
70
 
42
- That's it. The widget will bootstrap itself, connect to FlowEngage's backend, load chat history, and enable live agent handoff — all automatically.
71
+ ### Next.js App Router
72
+
73
+ - Put the provider + widget in a **Client Component** (file with `"use client"` at the top), or a client wrapper imported from `layout.tsx`.
74
+ - Keep a single provider tree so chat state is shared.
75
+
76
+ ### Yarn / monorepo
77
+
78
+ Ensure the package resolves once at app level so you do not mount duplicate providers.
79
+
80
+ ---
81
+
82
+ ## B. CDN / script tag (no React project required)
83
+
84
+ The embed build includes React and injects styles automatically. You do **not** import `styles.css` when using the script.
85
+
86
+ ### B1. FlowEngage CDN (recommended)
87
+
88
+ Use the hosted script (kept in sync with FlowEngage infrastructure):
89
+
90
+ ```html
91
+ <script
92
+ src="https://cdn.flowengage.com/flowengage-embed.js"
93
+ data-site-id="YOUR_SITE_ID"
94
+ defer>
95
+ </script>
96
+ ```
97
+
98
+ Place this **before `</body>`** on every page where the widget should appear, or in your global theme template.
99
+
100
+ ### B2. npm registry CDN (pin a version)
101
+
102
+ If you prefer to load the same artifact published to npm (useful for pinning or offline mirrors):
103
+
104
+ ```html
105
+ <!-- Replace 1.0.0 with the version you want -->
106
+ <script
107
+ src="https://cdn.jsdelivr.net/npm/@flowengage/react-chatbot@1.0.0/dist/flowengage-embed.js"
108
+ data-site-id="YOUR_SITE_ID"
109
+ defer>
110
+ </script>
111
+ ```
112
+
113
+ Equivalent path on unpkg:
114
+
115
+ `https://unpkg.com/@flowengage/react-chatbot@1.0.0/dist/flowengage-embed.js`
116
+
117
+ ### Auto-init attributes (`data-*`)
118
+
119
+ On the `<script>` tag:
120
+
121
+ | Attribute | Required | Description |
122
+ |-----------|----------|-------------|
123
+ | `data-site-id` | ✅ for auto-init | Your Site ID from the dashboard. |
124
+ | `data-api-url` | ❌ | Override API base URL (advanced; usually omit). |
125
+ | `data-widget-settings` | ❌ | JSON string of runtime widget overrides (theme, branding). Example: `'{"theme":{"primaryColor":"#2563EB"}}'` |
126
+
127
+ ### Manual initialization
128
+
129
+ If you cannot use `data-site-id` on the script tag:
130
+
131
+ ```html
132
+ <script src="https://cdn.flowengage.com/flowengage-embed.js" defer></script>
133
+ <script>
134
+ window.addEventListener('load', function () {
135
+ window.FlowEngage.init({
136
+ siteId: 'YOUR_SITE_ID',
137
+ widgetSettings: {
138
+ theme: { primaryColor: '#2563EB', position: 'bottom-right' },
139
+ branding: { headerName: 'Support', chatButtonText: 'Chat' },
140
+ },
141
+ });
142
+ });
143
+ </script>
144
+ ```
145
+
146
+ ### CDN API (`window.FlowEngage`)
147
+
148
+ | Method | Description |
149
+ |--------|-------------|
150
+ | `FlowEngage.init({ siteId, widgetSettings?, apiBaseUrl? })` | Mounts the widget. Safe to call after `DOMContentLoaded`. |
151
+ | `FlowEngage.destroy()` | Unmounts the widget and removes injected styles/container. Call before `init` again if you need to reconfigure. |
152
+
153
+ To open/close the panel from custom UI inside a **React** app, use the npm package and `useFlowEngage()` (`openWidget`, `closeWidget`, etc.). The standalone embed exposes `init` / `destroy` only.
154
+
155
+ ---
156
+
157
+ ## Optional: customization (npm)
158
+
159
+ Pass runtime overrides via `config` on the provider (merged with dashboard defaults):
160
+
161
+ ```jsx
162
+ <FlowEngageProvider
163
+ siteId="YOUR_SITE_ID"
164
+ config={{
165
+ widgetSettings: {
166
+ theme: {
167
+ primaryColor: '#FF5733',
168
+ position: 'bottom-left',
169
+ },
170
+ branding: {
171
+ headerName: 'Cool Support Assistant',
172
+ chatButtonText: 'Talk to us',
173
+ },
174
+ },
175
+ }}
176
+ >
177
+ <FlowEngageWidget />
178
+ </FlowEngageProvider>
179
+ ```
43
180
 
44
181
  ---
45
182
 
@@ -50,11 +187,11 @@ That's it. The widget will bootstrap itself, connect to FlowEngage's backend, lo
50
187
  | Prop | Type | Required | Description |
51
188
  |------|------|----------|-------------|
52
189
  | `siteId` | `string` | ✅ | Your Site ID from the FlowEngage dashboard |
53
- | `language` | `string` | ❌ | ISO 639-1 language code (default: `"en"`) |
190
+ | `config` | `object` | ❌ | `{ widgetSettings?: … }` merged with server config |
54
191
 
55
192
  ### `<FlowEngageWidget>`
56
193
 
57
- No props required. It reads all state from the nearest `FlowEngageProvider`.
194
+ No props required. It reads state from the nearest `FlowEngageProvider`.
58
195
 
59
196
  ---
60
197
 
@@ -69,7 +206,7 @@ function MyCustomButton() {
69
206
  const { openWidget, isOpen, chatHistory } = useFlowEngage();
70
207
 
71
208
  return (
72
- <button onClick={openWidget}>
209
+ <button type="button" onClick={() => openWidget({ notifyChatInitiated: true })}>
73
210
  Chat ({chatHistory.length} messages)
74
211
  </button>
75
212
  );
@@ -90,7 +227,6 @@ function MyCustomButton() {
90
227
  | `isLoading` | `boolean` | Waiting for AI response |
91
228
  | `isVoiceMode` | `boolean` | Voice mode active |
92
229
  | `isRateLimited` | `boolean` | Rate limit hit |
93
- | `language` | `string` | Current language |
94
230
  | `openWidget()` | `function` | Open the chat panel |
95
231
  | `closeWidget()` | `function` | Close the chat panel |
96
232
  | `toggleWidget()` | `function` | Toggle the panel |
@@ -100,64 +236,9 @@ function MyCustomButton() {
100
236
 
101
237
  ---
102
238
 
103
- ## Script Tag / CDN (No Framework Required)
104
-
105
- For plain HTML sites or any non-React app, use the self-contained embed script:
106
-
107
- ### Option A — Auto-init via `data` attribute (recommended)
108
-
109
- ```html
110
- <script
111
- src="https://cdn.flowengage.com/flowengage-embed.js"
112
- data-site-id="YOUR_SITE_ID">
113
- </script>
114
- ```
115
-
116
- ### Option B — Manual init
117
-
118
- ```html
119
- <script src="https://cdn.flowengage.com/flowengage-embed.js"></script>
120
- <script>
121
- FlowEngage.init({ siteId: 'YOUR_SITE_ID' });
122
- </script>
123
- ```
124
-
125
- ### Option C — With language
126
-
127
- ```html
128
- <script>
129
- FlowEngage.init({ siteId: 'YOUR_SITE_ID', language: 'ar' });
130
- </script>
131
- ```
132
-
133
- ### Programmatic control
134
-
135
- ```js
136
- // Remove the widget at any time
137
- FlowEngage.destroy();
138
-
139
- // Re-initialize
140
- FlowEngage.init({ siteId: 'YOUR_SITE_ID' });
141
- ```
142
-
143
- ---
144
-
145
- ## Multi-language Support
146
-
147
- The widget UI and AI responses can be localized. Pass a language code to the provider or the embed script:
148
-
149
- ```jsx
150
- <FlowEngageProvider siteId="YOUR_SITE_ID" language="fr">
151
- ```
152
-
153
- Supported languages depend on your FlowEngage tenant configuration.
154
-
155
- ---
156
-
157
239
  ## SPA Route Tracking
158
240
 
159
- The widget automatically tracks page views and session duration.
160
- For client-side routing (React Router, Next.js App Router, etc.), notify the tracker on route changes:
241
+ For client-side routing (React Router, Next.js App Router, etc.):
161
242
 
162
243
  ```jsx
163
244
  import { useFlowEngage } from '@flowengage/react-chatbot';
@@ -190,14 +271,14 @@ Your App
190
271
  └── Track: Socket.IO events → visitor session, page views
191
272
  ```
192
273
 
193
- All backend URLs are managed internally by FlowEngage. You never configure them.
274
+ Backend URLs are resolved by FlowEngage; you normally do not set them unless using `apiBaseUrl` (advanced).
194
275
 
195
276
  ---
196
277
 
197
278
  ## Getting Your Site ID
198
279
 
199
280
  1. Log in to the [FlowEngage Dashboard](https://app.flowengage.com)
200
- 2. Navigate to **Settings → Sites**
281
+ 2. Open **Integration Guide** or your site / workspace settings
201
282
  3. Copy the **Site ID** for your website
202
283
 
203
284
  ---