Skip to content

Commit d97ad42

Browse files
committed
chore: organize readme
1 parent b9ad883 commit d97ad42

File tree

3 files changed

+70
-183
lines changed

3 files changed

+70
-183
lines changed

README.md

Lines changed: 69 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Q&A Bot
22

3-
A React component for integrating the Q&A Bot into your application. The bot can operate in two modes: **floating** (chat button that opens/closes a window) or **embedded** (always visible inline).
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.
64

75
## Installation
86

@@ -34,94 +32,16 @@ The Q&A Bot supports two display modes:
3432
- **Floating Mode** (default): Shows a chat button that opens/closes a floating chat window
3533
- **Embedded Mode**: Always visible, embedded directly in the page content
3634

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-
4535
## Integration Methods
4636

47-
### Method 1: Auto-Detection by Element ID (Floating by Default)
48-
49-
Simply add a div with id `qa-bot` to your HTML:
50-
51-
```html
52-
<script src="https://unpkg.com/@snf/[email protected]/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.
5938

60-
Use the `embedded-qa-bot` class with optional data attributes:
39+
### React Component
6140

62-
```html
63-
<script src="https://unpkg.com/@snf/[email protected]/dist/access-qa-bot.standalone.js"></script>
64-
65-
<!-- Automatically creates an embedded chat widget -->
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/[email protected]/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-
botController.addMessage("Hello World!");
111-
botController.setBotIsLoggedIn(true);
112-
// (floating mode only)
113-
botController.openChat();
114-
botController.closeChat();
115-
botController.toggleChat();
116-
// Cleanup
117-
botController.destroy();
118-
```
119-
120-
**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.
121-
122-
## As a React Component
123-
124-
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
12545

12646
```jsx
12747
import React, { useRef, useState } from 'react';
@@ -161,8 +81,8 @@ function MyApp() {
16181
</button>
16282

16383
<QABot
164-
ref={botRef} // This is only needed if you want to add a message from outside the flow
165-
embedded={false} // true for embedded, false for floating
84+
ref={botRef} // only needed if you want use the addMessage function
85+
embedded={false}
16686
isLoggedIn={isLoggedIn}
16787
open={chatOpen}
16888
onOpenChange={setChatOpen}
@@ -174,112 +94,81 @@ function MyApp() {
17494
}
17595
```
17696
177-
**React Component Notes:**
178-
- Uses **controlled component pattern**: manage `open` and `isLoggedIn` state in your parent component
179-
- `onOpenChange` callback receives the new open state when user interacts with chat
180-
- For programmatic message injection, use the ref: `botRef.current?.addMessage("Hello!")`
181-
- `defaultOpen` prop not available - use `open` prop with `useState` instead
182-
- For state management (login, chat open/close), use props and state instead of imperative methods
183-
184-
## Configuration Properties
185-
186-
| Property | Type | Description |
187-
|----------|------|-------------|
188-
| `apiKey` / `api-key` | string | API key for authentication (defaults to demo key) |
189-
| `defaultOpen` / `default-open` | boolean | Whether floating chat opens initially (ignored in embedded mode) **React Component: Use `open` prop instead** |
190-
| `embedded` | boolean | **false** = floating mode, **true** = embedded mode |
191-
| `isLoggedIn` / `is-logged-in` | boolean | Sets initial login state and reacts to changes |
192-
| `loginUrl` / `login-url` | string | URL to redirect for login (default: '/login') |
193-
| `open` | boolean | **React Component only**: Controls chat window open state (floating mode only) |
194-
| `onOpenChange` | function | **React Component only**: Callback when chat window open state changes |
195-
| `ringEffect` / `ring-effect` | boolean | Enable phone ring animation on tooltip (floating mode only) |
196-
| `welcome` | string | Welcome message shown to the user |
197-
198-
**Note**: The React component uses a controlled component pattern with `open`/`onOpenChange`, while the JavaScript API uses `defaultOpen` for initial state.
97+
#### React Component Props
19998
200-
### CSS Custom Properties (Theming)
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 |
201109
202-
Customize the appearance by setting CSS custom properties on the container:
110+
### Standalone Javascript
203111
204112
```html
205-
<div id="qa-bot" style="
206-
--primary-color: #007bff;
207-
--secondary-color: #6c757d;
208-
--font-family: 'Arial', sans-serif;
209-
"></div>
210-
```
211-
212-
## Direct CDN Deployment
113+
<script src="https://unpkg.com/@snf/[email protected]/dist/access-qa-bot.standalone.js"></script>
213114

214-
For websites that don't use npm, include directly via CDN:
215-
216-
```html
217-
<!-- CSS (optional, for embedded styling) -->
218-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/necyberteam/[email protected]/build/static/css/main.css">
219-
220-
<!-- JavaScript -->
221-
<script src="https://cdn.jsdelivr.net/gh/necyberteam/[email protected]/dist/access-qa-bot.standalone.js"></script>
222-
223-
<!-- Your content -->
224115
<div id="qa-bot"></div>
225-
```
226116

227-
## Development and Testing
228-
229-
### Development Server (React Implementation)
230-
```bash
231-
npm start
232-
# Opens http://localhost:3000 with React dev server
233-
```
234-
235-
### Testing Standalone Integration
236-
```bash
237-
# Build the library and project
238-
npm run build:lib
239-
npm run build
240-
241-
# Serve the standalone demo files
242-
npx serve
243-
244-
# Then visit:
245-
# http://localhost:3000/index.html (integration demos)
117+
<script>
118+
qaBot({
119+
target: document.getElementById('qa-bot'),
120+
embedded: false,
121+
welcome: "Custom welcome message!",
122+
defaultOpen: false,
123+
});
124+
</script>
246125
```
247126
248-
## File Structure Guide
249-
250-
- **`index.html`** - Main demo showing all integration methods
251-
- **`public/index.html`** - React app template (Create React App)
252-
- **`build/index.html`** - Built React app
253-
- **`src/`** - Source code
254-
- **`components/QABot.js`** - Main React component
255-
- **`lib.js`** - React-backed implementation for all usage patterns
127+
#### Programmatic Control
256128
257-
## Important Notes
129+
When using the JavaScript API in plain HTML/JS (requires standalone bundle), you get a controller object with imperative methods:
258130
259-
1. **React-Backed Architecture**:
260-
- Everything uses React components internally for consistency
261-
- HTML/plain JS usage loads a React-based standalone bundle
262-
- Single implementation reduces complexity and bugs
131+
```javascript
132+
const botController = qaBot({
133+
target: document.getElementById('qa-bot'),
134+
embedded: false,
135+
welcome: "Custom welcome message!",
136+
defaultOpen: false,
137+
});
263138

264-
2. **Embedded vs Floating**:
265-
- Embedded mode is always visible and ignores `defaultOpen`
266-
- Floating mode shows a chat button; `defaultOpen` controls initial state
267-
- Chat window controls (`openChat`, `closeChat`, `toggleChat`) only work in floating mode
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+
```
268148
269-
3. **Ring Effect**:
270-
- Only works in floating mode when the tooltip is visible
271-
- Triggers a phone-like ring animation to draw attention
272-
- Activates once when the bot is first loaded (500ms delay)
273-
- Won't repeat if user has already interacted with the chat
149+
#### JavaScript API Configuration
274150
275-
4. **Auto-Detection**: The standalone script automatically detects and initializes:
276-
- `#qa-bot` → Floating mode
277-
- `.embedded-qa-bot` → Embedded mode
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 |
278161
279-
5. **API Key**: Defaults to demo key if not provided
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.
280163
281-
6. **Browser Support**: Uses modern browser features; consider polyfills for older browsers
164+
### CSS Custom Properties (Theming)
282165
283-
## Examples Repository
166+
Customize the appearance by setting CSS custom properties on the container:
284167
285-
See the demo files in this repository for complete working examples of all integration methods.
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+
```

src/components/QABot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const QABot = React.forwardRef((props, botRef) => {
126126
useRingEffect(ringEffect, containerRef);
127127

128128
return (
129-
<div className={`qa-bot ${embedded ? "embedded-qa-bot" : ""}`} ref={containerRef}>
129+
<div className={`qa-bot ${embedded ? "embedded-qa-bot" : ""}`} ref={containerRef}>
130130
<ChatBotProvider>
131131
<BotController
132132
ref={botRef}

src/components/ThumbsUpThumbsDown.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ const ThumbsUpThumbsDown = ({ sessionId, currentQueryId, className = '', style }
6565
'X-Feedback': isPositive ? 1 : 0
6666
};
6767

68-
// console.log('| 📫 headers for feedback:', headers);
69-
7068
try {
7169
const requestOptions = {
7270
method: 'POST',

0 commit comments

Comments
 (0)