@snf/qa-bot-core 0.2.4 → 0.2.5
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 +102 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ function App() {
|
|
|
26
26
|
apiKey="your-api-key"
|
|
27
27
|
qaEndpoint="https://your-api.com/chat"
|
|
28
28
|
welcomeMessage="Hello! How can I help you today?"
|
|
29
|
+
isLoggedIn={true}
|
|
29
30
|
/>
|
|
30
31
|
);
|
|
31
32
|
}
|
|
@@ -41,8 +42,12 @@ Customize appearance and behavior:
|
|
|
41
42
|
ratingEndpoint="https://your-api.com/rating"
|
|
42
43
|
welcomeMessage="Hello! How can I help you today?"
|
|
43
44
|
|
|
44
|
-
//
|
|
45
|
-
|
|
45
|
+
// Authentication (required)
|
|
46
|
+
isLoggedIn={true}
|
|
47
|
+
allowAnonAccess={false}
|
|
48
|
+
loginUrl="/login"
|
|
49
|
+
|
|
50
|
+
// Window control
|
|
46
51
|
open={false}
|
|
47
52
|
onOpenChange={(isOpen) => console.log('Chat is now', isOpen ? 'open' : 'closed')}
|
|
48
53
|
|
|
@@ -77,6 +82,7 @@ const bot = qaBot({
|
|
|
77
82
|
qaEndpoint: 'https://your-api.com/chat',
|
|
78
83
|
ratingEndpoint: 'https://your-api.com/rating',
|
|
79
84
|
welcomeMessage: "Hello! How can I help you today?",
|
|
85
|
+
isLoggedIn: true,
|
|
80
86
|
primaryColor: '#24292e',
|
|
81
87
|
secondaryColor: '#586069',
|
|
82
88
|
botName: 'Demo Assistant',
|
|
@@ -102,6 +108,7 @@ bot.destroy();
|
|
|
102
108
|
qaEndpoint: 'https://your-api.com/chat',
|
|
103
109
|
ratingEndpoint: 'https://your-api.com/rating',
|
|
104
110
|
welcomeMessage: "Hello! How can I help you today?",
|
|
111
|
+
isLoggedIn: true,
|
|
105
112
|
primaryColor: '#24292e',
|
|
106
113
|
secondaryColor: '#586069',
|
|
107
114
|
botName: 'Demo Assistant',
|
|
@@ -119,9 +126,10 @@ bot.destroy();
|
|
|
119
126
|
| `apiKey` | string | ✅ | API key for your Q&A service |
|
|
120
127
|
| `qaEndpoint` | string | ✅ | Q&A API endpoint URL |
|
|
121
128
|
| `welcomeMessage` | string | ✅ | Initial greeting message |
|
|
129
|
+
| `isLoggedIn` | boolean | ✅ | Whether the user is logged in. Controls header icon and Q&A access gating |
|
|
122
130
|
| `ratingEndpoint` | string | ❌ | Rating API endpoint URL (enables thumbs up/down) |
|
|
123
|
-
| `
|
|
124
|
-
| `loginUrl` | string | ❌ | Login URL
|
|
131
|
+
| `allowAnonAccess` | boolean | ❌ | Allow Q&A access even when not logged in (default: `false`) |
|
|
132
|
+
| `loginUrl` | string | ❌ | Login URL for the login button when not logged in (default: `/login`) |
|
|
125
133
|
| `open` | boolean | ❌ | Control chat window open/closed state |
|
|
126
134
|
| `onOpenChange` | function | ❌ | Callback when chat window state changes: `(open: boolean) => void` |
|
|
127
135
|
| `primaryColor` | string | ❌ | Main theme color (default: `#1a5b6e`) |
|
|
@@ -134,39 +142,55 @@ bot.destroy();
|
|
|
134
142
|
| `embedded` | boolean | ❌ | Embedded mode (default: `false`) |
|
|
135
143
|
| `footerText` | string | ❌ | Footer text |
|
|
136
144
|
| `footerLink` | string | ❌ | Footer link URL |
|
|
145
|
+
| `customFlow` | Flow | ❌ | Custom flow steps to merge with built-in Q&A flow (see Custom Flows section) |
|
|
137
146
|
|
|
138
147
|
## Features
|
|
139
148
|
|
|
140
149
|
### Login State Management
|
|
141
150
|
|
|
142
|
-
The bot
|
|
151
|
+
The bot manages authentication state through the `isLoggedIn` prop:
|
|
143
152
|
|
|
144
|
-
- **
|
|
145
|
-
- **
|
|
153
|
+
- **Logged in (`isLoggedIn={true}`)**: Shows user icon in header, Q&A is fully accessible
|
|
154
|
+
- **Not logged in (`isLoggedIn={false}`)**: Shows login button in header, Q&A is gated (prompts to log in)
|
|
146
155
|
|
|
147
156
|
Example:
|
|
148
157
|
```jsx
|
|
149
|
-
const [
|
|
158
|
+
const [userLoggedIn, setUserLoggedIn] = useState(false);
|
|
150
159
|
|
|
151
160
|
<QABot
|
|
152
161
|
apiKey="your-api-key"
|
|
153
162
|
qaEndpoint="https://your-api.com/chat"
|
|
154
163
|
welcomeMessage="Hello! How can I help you today?"
|
|
155
|
-
|
|
164
|
+
isLoggedIn={userLoggedIn}
|
|
156
165
|
loginUrl="https://your-app.com/login"
|
|
157
166
|
/>
|
|
158
167
|
```
|
|
159
168
|
|
|
160
|
-
When the user is not logged in (`
|
|
169
|
+
When the user is not logged in (`isLoggedIn={false}`):
|
|
161
170
|
- The login button appears in the chat header
|
|
162
171
|
- Clicking it opens the `loginUrl` in a new tab
|
|
163
|
-
-
|
|
172
|
+
- Q&A flow is gated and prompts users to log in
|
|
164
173
|
|
|
165
|
-
When the user is logged in (`
|
|
174
|
+
When the user is logged in (`isLoggedIn={true}`):
|
|
166
175
|
- A user icon appears in the chat header
|
|
167
|
-
- The chat input becomes active
|
|
168
176
|
- Users can ask questions normally
|
|
169
177
|
|
|
178
|
+
#### Anonymous Access
|
|
179
|
+
|
|
180
|
+
If you want to allow Q&A access without requiring login, use the `allowAnonAccess` prop:
|
|
181
|
+
|
|
182
|
+
```jsx
|
|
183
|
+
<QABot
|
|
184
|
+
apiKey="your-api-key"
|
|
185
|
+
qaEndpoint="https://your-api.com/chat"
|
|
186
|
+
welcomeMessage="Hello! How can I help you today?"
|
|
187
|
+
isLoggedIn={false}
|
|
188
|
+
allowAnonAccess={true}
|
|
189
|
+
/>
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
This bypasses the login gate for Q&A while still showing the login button in the header. Note that custom flows (if any) are unaffected by this setting.
|
|
193
|
+
|
|
170
194
|
### Chat Window Control
|
|
171
195
|
|
|
172
196
|
Control the chat window open/closed state programmatically:
|
|
@@ -178,6 +202,7 @@ const [chatOpen, setChatOpen] = useState(false);
|
|
|
178
202
|
apiKey="your-api-key"
|
|
179
203
|
qaEndpoint="https://your-api.com/chat"
|
|
180
204
|
welcomeMessage="Hello! How can I help you today?"
|
|
205
|
+
isLoggedIn={true}
|
|
181
206
|
open={chatOpen}
|
|
182
207
|
onOpenChange={setChatOpen}
|
|
183
208
|
/>
|
|
@@ -203,6 +228,7 @@ const botRef = useRef();
|
|
|
203
228
|
apiKey="your-api-key"
|
|
204
229
|
qaEndpoint="https://your-api.com/chat"
|
|
205
230
|
welcomeMessage="Hello! How can I help you today?"
|
|
231
|
+
isLoggedIn={true}
|
|
206
232
|
/>
|
|
207
233
|
|
|
208
234
|
// Available methods:
|
|
@@ -236,6 +262,7 @@ Example of embedded mode:
|
|
|
236
262
|
apiKey="your-api-key"
|
|
237
263
|
qaEndpoint="https://your-api.com/chat"
|
|
238
264
|
welcomeMessage="Hello! How can I help you today?"
|
|
265
|
+
isLoggedIn={true}
|
|
239
266
|
embedded={true}
|
|
240
267
|
/>
|
|
241
268
|
</div>
|
|
@@ -243,6 +270,67 @@ Example of embedded mode:
|
|
|
243
270
|
|
|
244
271
|
**Note:** When `embedded={true}`, the `open` and `onOpenChange` props are ignored, and the imperative methods `openChat()`, `closeChat()`, and `toggleChat()` have no effect.
|
|
245
272
|
|
|
273
|
+
### Custom Flows
|
|
274
|
+
|
|
275
|
+
You can extend the bot with custom flow steps using the `customFlow` prop. This allows you to add ticket creation, feedback forms, or other interactive workflows that merge with the built-in Q&A flow.
|
|
276
|
+
|
|
277
|
+
```jsx
|
|
278
|
+
import QABot from '@snf/qa-bot-core';
|
|
279
|
+
|
|
280
|
+
const myCustomFlow = {
|
|
281
|
+
submit_ticket: {
|
|
282
|
+
message: "I'll help you submit a ticket. What's the issue?",
|
|
283
|
+
path: "ticket_details"
|
|
284
|
+
},
|
|
285
|
+
ticket_details: {
|
|
286
|
+
message: "Thanks! Your ticket has been submitted.",
|
|
287
|
+
path: "start"
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
<QABot
|
|
292
|
+
apiKey="your-api-key"
|
|
293
|
+
qaEndpoint="https://your-api.com/chat"
|
|
294
|
+
welcomeMessage="Hello! How can I help you today?"
|
|
295
|
+
isLoggedIn={true}
|
|
296
|
+
customFlow={myCustomFlow}
|
|
297
|
+
/>
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Custom flows are merged into the flow object, so your custom steps can reference built-in steps and vice versa.
|
|
301
|
+
|
|
302
|
+
#### Flow Settings Utility
|
|
303
|
+
|
|
304
|
+
When building custom flows, you may encounter a react-chatbotify quirk where `chatDisabled` state persists across step transitions. The `applyFlowSettings` utility helps manage this:
|
|
305
|
+
|
|
306
|
+
```javascript
|
|
307
|
+
import { applyFlowSettings } from '@snf/qa-bot-core';
|
|
308
|
+
|
|
309
|
+
const myFlow = {
|
|
310
|
+
choose_option: {
|
|
311
|
+
message: "Select an option:",
|
|
312
|
+
options: ["Option A", "Option B"],
|
|
313
|
+
path: "next_step"
|
|
314
|
+
},
|
|
315
|
+
next_step: {
|
|
316
|
+
message: "You selected an option!",
|
|
317
|
+
path: "start"
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
// Auto-disable chat input on steps with options/checkboxes
|
|
322
|
+
const processedFlow = applyFlowSettings(myFlow, {
|
|
323
|
+
disableOnOptions: true
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
<QABot
|
|
327
|
+
// ...other props
|
|
328
|
+
customFlow={processedFlow}
|
|
329
|
+
/>
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
The `disableOnOptions: true` setting automatically sets `chatDisabled: true` for steps that have `options` or `checkboxes`, and `chatDisabled: false` for steps without them (unless you've explicitly set `chatDisabled` yourself).
|
|
333
|
+
|
|
246
334
|
### Session Management
|
|
247
335
|
|
|
248
336
|
The bot automatically manages conversation sessions with unique session IDs:
|
|
@@ -323,7 +411,7 @@ The demo runs at `http://localhost:3000` and includes:
|
|
|
323
411
|
- Displays API endpoints for verification
|
|
324
412
|
|
|
325
413
|
**Dynamic Props**
|
|
326
|
-
- Toggle `
|
|
414
|
+
- Toggle `isLoggedIn` prop to simulate login/logout states
|
|
327
415
|
- Toggle `open` prop to control chat window state
|
|
328
416
|
- Toggle `embedded` prop to switch between floating and embedded modes
|
|
329
417
|
|
package/package.json
CHANGED