@snf/access-qa-bot 2.1.0-rc.6 → 2.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/README.md +69 -185
- package/build/static/js/main.js +1 -1
- package/build/static/js/main.js.map +1 -1
- package/dist/access-qa-bot.js +1 -1
- package/dist/access-qa-bot.js.map +1 -1
- package/dist/access-qa-bot.standalone.js +4 -4
- package/dist/access-qa-bot.standalone.js.map +1 -1
- package/dist/access-qa-bot.umd.cjs +1 -1
- package/dist/access-qa-bot.umd.cjs.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# Q&A Bot
|
|
2
2
|
|
|
3
|
-
A React component for integrating the Q&A Bot into your application.
|
|
4
|
-
|
|
5
|
-
**Architecture**: Everything is React-backed for consistency and simplicity. HTML/plain JS usage loads a React-based standalone bundle.
|
|
3
|
+
A React component for integrating the Q&A Bot into your application. Also includes a standalone bundle for plain HTML/JS usage.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
@@ -34,99 +32,16 @@ The Q&A Bot supports two display modes:
|
|
|
34
32
|
- **Floating Mode** (default): Shows a chat button that opens/closes a floating chat window
|
|
35
33
|
- **Embedded Mode**: Always visible, embedded directly in the page content
|
|
36
34
|
|
|
37
|
-
**All integration methods support both modes**, but have different defaults:
|
|
38
|
-
|
|
39
|
-
| Method | Default Mode | Override |
|
|
40
|
-
|--------|--------------|----------|
|
|
41
|
-
| Element ID (`#qa-bot`) | Floating | Set `embedded: true` |
|
|
42
|
-
| CSS Class (`.embedded-qa-bot`) | Embedded | n/a |
|
|
43
|
-
| JavaScript API | Floating | Set `embedded: true` |
|
|
44
|
-
|
|
45
35
|
## Integration Methods
|
|
46
36
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
Simply add a div with id `qa-bot` to your HTML:
|
|
50
|
-
|
|
51
|
-
```html
|
|
52
|
-
<script src="https://unpkg.com/@snf/access-qa-bot@0.2.0/dist/access-qa-bot.standalone.js"></script>
|
|
53
|
-
|
|
54
|
-
<!-- Automatically creates a floating chat button -->
|
|
55
|
-
<div id="qa-bot"></div>
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Method 2: Auto-Detection by CSS Class (Embedded by Default)
|
|
37
|
+
The QABot can be integrated using a standalone javascript function, or as a react/preact component.
|
|
59
38
|
|
|
60
|
-
|
|
39
|
+
### React Component
|
|
61
40
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
<div class="embedded-qa-bot"
|
|
67
|
-
data-welcome="Hello!"></div>
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Method 3: Programmatic JavaScript API (Floating by Default)
|
|
71
|
-
|
|
72
|
-
Call the `qaBot()` function with full control:
|
|
73
|
-
|
|
74
|
-
```html
|
|
75
|
-
<script src="https://unpkg.com/@snf/access-qa-bot@0.2.0/dist/access-qa-bot.standalone.js"></script>
|
|
76
|
-
|
|
77
|
-
<div id="my-bot-container"></div>
|
|
78
|
-
|
|
79
|
-
<script>
|
|
80
|
-
// Check if user is logged in by looking for auth cookie
|
|
81
|
-
function isUserLoggedIn() {
|
|
82
|
-
return document.cookie.split(';').some(cookie => {
|
|
83
|
-
return cookie.trim().startsWith('SESSaccesscisso=');
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
window.addEventListener('load', function() {
|
|
88
|
-
const botController = qaBot({
|
|
89
|
-
target: document.getElementById('my-bot-container'),
|
|
90
|
-
embedded: false, // false = floating (default), true = embedded
|
|
91
|
-
welcome: "Custom welcome message!",
|
|
92
|
-
isLoggedIn: isUserLoggedIn(),
|
|
93
|
-
defaultOpen: false,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// Use the controller to interact with the bot
|
|
97
|
-
botController.addMessage("Hello from JavaScript!");
|
|
98
|
-
botController.openChat(); // Only works in floating mode
|
|
99
|
-
});
|
|
100
|
-
</script>
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## Programmatic Control
|
|
104
|
-
|
|
105
|
-
When using the JavaScript API in plain HTML/JS (requires standalone bundle), you get a controller object with these methods:
|
|
106
|
-
|
|
107
|
-
```javascript
|
|
108
|
-
const botController = qaBot({...});
|
|
109
|
-
|
|
110
|
-
// Add a message to the chat
|
|
111
|
-
botController.addMessage("Hello World!");
|
|
112
|
-
|
|
113
|
-
// Set user login status
|
|
114
|
-
botController.setBotIsLoggedIn(true);
|
|
115
|
-
|
|
116
|
-
// Control chat window (floating mode only)
|
|
117
|
-
botController.openChat();
|
|
118
|
-
botController.closeChat();
|
|
119
|
-
botController.toggleChat();
|
|
120
|
-
|
|
121
|
-
// Cleanup
|
|
122
|
-
botController.destroy();
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
**Note**: The `qaBot()` function requires the standalone bundle (`access-qa-bot.standalone.js`) to be loaded first. React/Preact applications should use the `<QABot />` component instead.
|
|
126
|
-
|
|
127
|
-
## As a React Component
|
|
128
|
-
|
|
129
|
-
For React applications, import and use the component directly. If you want to be able to imperatively add a message to the chat, you can use the ref to do so.
|
|
41
|
+
For React applications, import and use the component directly.
|
|
42
|
+
- To control the chat programmatically, manage `open` and `isLoggedIn` state in your parent component.
|
|
43
|
+
- Use `onOpenChange` to keep your state in sync with user interactions.
|
|
44
|
+
- You can imperatively add a message to the bot using the `addMessage` function
|
|
130
45
|
|
|
131
46
|
```jsx
|
|
132
47
|
import React, { useRef, useState } from 'react';
|
|
@@ -166,8 +81,8 @@ function MyApp() {
|
|
|
166
81
|
</button>
|
|
167
82
|
|
|
168
83
|
<QABot
|
|
169
|
-
ref={botRef} //
|
|
170
|
-
embedded={false}
|
|
84
|
+
ref={botRef} // only needed if you want use the addMessage function
|
|
85
|
+
embedded={false}
|
|
171
86
|
isLoggedIn={isLoggedIn}
|
|
172
87
|
open={chatOpen}
|
|
173
88
|
onOpenChange={setChatOpen}
|
|
@@ -179,112 +94,81 @@ function MyApp() {
|
|
|
179
94
|
}
|
|
180
95
|
```
|
|
181
96
|
|
|
182
|
-
|
|
183
|
-
- Uses **controlled component pattern**: manage `open` and `isLoggedIn` state in your parent component
|
|
184
|
-
- `onOpenChange` callback receives the new open state when user interacts with chat
|
|
185
|
-
- For programmatic message injection, use the ref: `botRef.current?.addMessage("Hello!")`
|
|
186
|
-
- `defaultOpen` prop not available - use `open` prop with `useState` instead
|
|
187
|
-
- For state management (login, chat open/close), use props and state instead of imperative methods
|
|
188
|
-
|
|
189
|
-
## Configuration Properties
|
|
190
|
-
|
|
191
|
-
| Property | Type | Description |
|
|
192
|
-
|----------|------|-------------|
|
|
193
|
-
| `apiKey` / `api-key` | string | API key for authentication (defaults to demo key) |
|
|
194
|
-
| `defaultOpen` / `default-open` | boolean | Whether floating chat opens initially (ignored in embedded mode) **React Component: Use `open` prop instead** |
|
|
195
|
-
| `embedded` | boolean | **false** = floating mode, **true** = embedded mode |
|
|
196
|
-
| `isLoggedIn` / `is-logged-in` | boolean | Sets initial login state and reacts to changes |
|
|
197
|
-
| `loginUrl` / `login-url` | string | URL to redirect for login (default: '/login') |
|
|
198
|
-
| `open` | boolean | **React Component only**: Controls chat window open state (floating mode only) |
|
|
199
|
-
| `onOpenChange` | function | **React Component only**: Callback when chat window open state changes |
|
|
200
|
-
| `ringEffect` / `ring-effect` | boolean | Enable phone ring animation on tooltip (floating mode only) |
|
|
201
|
-
| `welcome` | string | Welcome message shown to the user |
|
|
202
|
-
|
|
203
|
-
**Note**: The React component uses a controlled component pattern with `open`/`onOpenChange`, while the JavaScript API uses `defaultOpen` for initial state.
|
|
204
|
-
|
|
205
|
-
### CSS Custom Properties (Theming)
|
|
206
|
-
|
|
207
|
-
Customize the appearance by setting CSS custom properties on the container:
|
|
208
|
-
|
|
209
|
-
```html
|
|
210
|
-
<div id="qa-bot" style="
|
|
211
|
-
--primary-color: #007bff;
|
|
212
|
-
--secondary-color: #6c757d;
|
|
213
|
-
--font-family: 'Arial', sans-serif;
|
|
214
|
-
"></div>
|
|
215
|
-
```
|
|
97
|
+
#### React Component Props
|
|
216
98
|
|
|
217
|
-
|
|
99
|
+
| Property | Type | Default | Description |
|
|
100
|
+
|----------|------|---------|-------------|
|
|
101
|
+
| `apiKey` | string | `"demo-key"` | API key for authentication |
|
|
102
|
+
| `embedded` | boolean | `false` | Floating or embedded mode |
|
|
103
|
+
| `isLoggedIn` | boolean | `false` | User login state |
|
|
104
|
+
| `loginUrl` | string | `"/login"` | Login redirect URL |
|
|
105
|
+
| `open` | boolean | - | Controls chat window (floating mode only) |
|
|
106
|
+
| `onOpenChange` | function | - | Chat window state change callback |
|
|
107
|
+
| `ringEffect` | boolean | `true` | Phone ring animation on tooltip |
|
|
108
|
+
| `welcome` | string | - | Welcome message |
|
|
218
109
|
|
|
219
|
-
|
|
110
|
+
### Standalone Javascript
|
|
220
111
|
|
|
221
112
|
```html
|
|
222
|
-
|
|
223
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/necyberteam/qa-bot@v0.2.0/build/static/css/main.css">
|
|
224
|
-
|
|
225
|
-
<!-- JavaScript -->
|
|
226
|
-
<script src="https://cdn.jsdelivr.net/gh/necyberteam/qa-bot@v0.2.0/dist/access-qa-bot.standalone.js"></script>
|
|
113
|
+
<script src="https://unpkg.com/@snf/access-qa-bot@2.1.0/dist/access-qa-bot.standalone.js"></script>
|
|
227
114
|
|
|
228
|
-
<!-- Your content -->
|
|
229
115
|
<div id="qa-bot"></div>
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
## Development and Testing
|
|
233
|
-
|
|
234
|
-
### Development Server (React Implementation)
|
|
235
|
-
```bash
|
|
236
|
-
npm start
|
|
237
|
-
# Opens http://localhost:3000 with React dev server
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
### Testing Standalone Integration
|
|
241
|
-
```bash
|
|
242
|
-
# Build the library and project
|
|
243
|
-
npm run build:lib
|
|
244
|
-
npm run build
|
|
245
|
-
|
|
246
|
-
# Serve the standalone demo files
|
|
247
|
-
npx serve
|
|
248
116
|
|
|
249
|
-
|
|
250
|
-
|
|
117
|
+
<script>
|
|
118
|
+
qaBot({
|
|
119
|
+
target: document.getElementById('qa-bot'),
|
|
120
|
+
embedded: false,
|
|
121
|
+
welcome: "Custom welcome message!",
|
|
122
|
+
defaultOpen: false,
|
|
123
|
+
});
|
|
124
|
+
</script>
|
|
251
125
|
```
|
|
252
126
|
|
|
253
|
-
|
|
127
|
+
#### Programmatic Control
|
|
254
128
|
|
|
255
|
-
|
|
256
|
-
- **`public/index.html`** - React app template (Create React App)
|
|
257
|
-
- **`build/index.html`** - Built React app
|
|
258
|
-
- **`src/`** - Source code
|
|
259
|
-
- **`components/QABot.js`** - Main React component
|
|
260
|
-
- **`lib.js`** - React-backed implementation for all usage patterns
|
|
129
|
+
When using the JavaScript API in plain HTML/JS (requires standalone bundle), you get a controller object with imperative methods:
|
|
261
130
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
131
|
+
```javascript
|
|
132
|
+
const botController = qaBot({
|
|
133
|
+
target: document.getElementById('qa-bot'),
|
|
134
|
+
embedded: false,
|
|
135
|
+
welcome: "Custom welcome message!",
|
|
136
|
+
defaultOpen: false,
|
|
137
|
+
});
|
|
268
138
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
139
|
+
botController.addMessage("Hello World!");
|
|
140
|
+
botController.setBotIsLoggedIn(true);
|
|
141
|
+
// (floating mode only)
|
|
142
|
+
botController.openChat();
|
|
143
|
+
botController.closeChat();
|
|
144
|
+
botController.toggleChat();
|
|
145
|
+
// Cleanup
|
|
146
|
+
botController.destroy();
|
|
147
|
+
```
|
|
273
148
|
|
|
274
|
-
|
|
275
|
-
- Only works in floating mode when the tooltip is visible
|
|
276
|
-
- Triggers a phone-like ring animation to draw attention
|
|
277
|
-
- Activates once when the bot is first loaded (500ms delay)
|
|
278
|
-
- Won't repeat if user has already interacted with the chat
|
|
149
|
+
#### JavaScript API Configuration
|
|
279
150
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
151
|
+
| Property | Type | Default | Description |
|
|
152
|
+
|----------|------|---------|-------------|
|
|
153
|
+
| `target` | HTMLElement | - | **Required**: DOM element to render into |
|
|
154
|
+
| `apiKey` | string | `"demo-key"` | API key for authentication |
|
|
155
|
+
| `defaultOpen` | boolean | `false` | Initial chat window state |
|
|
156
|
+
| `embedded` | boolean | `false` | Floating or embedded mode |
|
|
157
|
+
| `isLoggedIn` | boolean | `false` | User login state |
|
|
158
|
+
| `loginUrl` | string | `"/login"` | Login redirect URL |
|
|
159
|
+
| `ringEffect` | boolean | `true` | Phone ring animation on tooltip |
|
|
160
|
+
| `welcome` | string | - | Welcome message |
|
|
283
161
|
|
|
284
|
-
|
|
162
|
+
> **More Examples**: See `index.html` in this repository for examples including login state management, embedded mode, and programmatic control. Run the react app to see the same in a react context.
|
|
285
163
|
|
|
286
|
-
|
|
164
|
+
### CSS Custom Properties (Theming)
|
|
287
165
|
|
|
288
|
-
|
|
166
|
+
Customize the appearance by setting CSS custom properties on the container:
|
|
289
167
|
|
|
290
|
-
|
|
168
|
+
```html
|
|
169
|
+
<div id="qa-bot" style="
|
|
170
|
+
--primary-color: #007bff;
|
|
171
|
+
--secondary-color: #6c757d;
|
|
172
|
+
--font-family: 'Arial', sans-serif;
|
|
173
|
+
"></div>
|
|
174
|
+
```
|