rushchatbot 1.6.7
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/INTEGRATION.md +559 -0
- package/index.html +13 -0
- package/package/INTEGRATION.md +717 -0
- package/package/README.md +717 -0
- package/package/package-lock.json +3221 -0
- package/package/package.json +101 -0
- package/package/src/cli/index.ts +94 -0
- package/package/src/client/ChatWidget.tsx +163 -0
- package/package/src/client.ts +2 -0
- package/package/src/core/RushChatbot.ts +192 -0
- package/package/src/index.ts +5 -0
- package/package/src/server/guardrails.ts +107 -0
- package/package/src/server/index.ts +210 -0
- package/package/src/server/matcher.ts +140 -0
- package/package/src/shared/types.ts +58 -0
- package/package/src/shims-vue.d.ts +5 -0
- package/package/src/vanilla/index.ts +302 -0
- package/package/src/vanilla.ts +3 -0
- package/package/src/vue/ChatWidget.vue +198 -0
- package/package/src/vue.ts +3 -0
- package/package/src/vue2/ChatWidget.vue +204 -0
- package/package/src/vue2.ts +3 -0
- package/package/tsconfig.json +19 -0
- package/package/vite.config.ts +86 -0
- package/package.json +35 -0
- package/public/favicon.svg +1 -0
- package/public/icons.svg +24 -0
- package/server/data/analytics.json +795 -0
- package/server/data/chatbot.config.json +26 -0
- package/server/data/questions.json +238 -0
- package/server/data/questions.tl.json +182 -0
- package/server/index.ts +11 -0
- package/server/lib/guardrails.ts +107 -0
- package/server/lib/matcher.ts +140 -0
- package/server/routes/chat.ts +180 -0
- package/server/tsconfig.json +11 -0
- package/src/App.css +184 -0
- package/src/App.tsx +135 -0
- package/src/assets/hero.png +0 -0
- package/src/assets/react.svg +1 -0
- package/src/assets/vite.svg +1 -0
- package/src/components/ChatWidget.tsx +417 -0
- package/src/components/QuestionTree.tsx +57 -0
- package/src/hooks/useChatData.ts +49 -0
- package/src/index.css +111 -0
- package/src/main.tsx +10 -0
- package/src/types/index.ts +40 -0
- package/tsconfig.app.json +26 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +23 -0
- package/vite.config.ts +7 -0
package/INTEGRATION.md
ADDED
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
# RushChatbot
|
|
2
|
+
|
|
3
|
+
**Version:** 1.5.1
|
|
4
|
+
|
|
5
|
+
Embeddable hybrid chatbot plugin that combines a click-based FAQ tree with a free-text query engine backed by n8n. Ships as an npm package with a Node.js/Express server and a React widget.
|
|
6
|
+
|
|
7
|
+
**Features:**
|
|
8
|
+
- Click-based FAQ question tree with subquestions
|
|
9
|
+
- Fuzzy + keyword matching against your config
|
|
10
|
+
- n8n webhook fallback for unmatched queries
|
|
11
|
+
- Markdown rendering (bold, lists, headings)
|
|
12
|
+
- Multi-bubble paragraph responses
|
|
13
|
+
- Draggable floating chat button
|
|
14
|
+
- Tagalog (TL) language support
|
|
15
|
+
- Input validation and profanity guardrails
|
|
16
|
+
- Session-based analytics
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Table of Contents
|
|
21
|
+
|
|
22
|
+
1. [Requirements](#1-requirements)
|
|
23
|
+
2. [Installation](#2-installation)
|
|
24
|
+
3. [Scaffold Config Files](#3-scaffold-config-files)
|
|
25
|
+
4. [Configure the Chatbot](#4-configure-the-chatbot)
|
|
26
|
+
5. [Build the FAQ Tree](#5-build-the-faq-tree)
|
|
27
|
+
6. [Start the Server](#6-start-the-server)
|
|
28
|
+
7. [Embed the Widget](#7-embed-the-widget)
|
|
29
|
+
8. [Floating Button Behavior](#8-floating-button-behavior)
|
|
30
|
+
9. [n8n Webhook Setup](#9-n8n-webhook-setup)
|
|
31
|
+
10. [n8n Response Formats](#10-n8n-response-formats)
|
|
32
|
+
11. [Environment Variables](#11-environment-variables)
|
|
33
|
+
12. [API Reference](#12-api-reference)
|
|
34
|
+
13. [Analytics](#13-analytics)
|
|
35
|
+
14. [Troubleshooting](#14-troubleshooting)
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 1. Requirements
|
|
40
|
+
|
|
41
|
+
| Requirement | Version |
|
|
42
|
+
|---|---|
|
|
43
|
+
| Node.js | >= 18.0.0 |
|
|
44
|
+
| npm | >= 9.0.0 |
|
|
45
|
+
| React (for widget) | >= 18.0.0 |
|
|
46
|
+
| n8n instance | Any hosted or self-hosted |
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 2. Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install rushchatbot
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 3. Scaffold Config Files
|
|
59
|
+
|
|
60
|
+
Run the init command to generate the required config and questions files in a directory of your choice:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npx rushchatbot init ./chatbot
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
This creates three files:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
chatbot/
|
|
70
|
+
├── chatbot.config.json ← branding, n8n, chat settings
|
|
71
|
+
├── questions.json ← English FAQ tree
|
|
72
|
+
└── questions.tl.json ← Tagalog FAQ tree (optional)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 4. Configure the Chatbot
|
|
78
|
+
|
|
79
|
+
Edit `chatbot.config.json` with your settings:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"branding": {
|
|
84
|
+
"title": "My Support Bot",
|
|
85
|
+
"subtitle": "How can we help you today?",
|
|
86
|
+
"theme": {
|
|
87
|
+
"primaryColor": "#4F46E5",
|
|
88
|
+
"backgroundColor": "#FFFFFF",
|
|
89
|
+
"userBubbleColor": "#4F46E5",
|
|
90
|
+
"botBubbleColor": "#F3F4F6",
|
|
91
|
+
"textColor": "#111827",
|
|
92
|
+
"fontFamily": "Inter, sans-serif"
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"n8n": {
|
|
96
|
+
"webhookUrl": "https://your-n8n.com/webhook/your-webhook-id",
|
|
97
|
+
"timeoutMs": 55000
|
|
98
|
+
},
|
|
99
|
+
"chat": {
|
|
100
|
+
"welcomeMessage": "Hi! Choose a question below or type your own.",
|
|
101
|
+
"fallbackMessage": "Let me look that up for you...",
|
|
102
|
+
"matchThreshold": 0.4,
|
|
103
|
+
"showPreQuestionsOnStart": true,
|
|
104
|
+
"language": "en"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Config field reference
|
|
110
|
+
|
|
111
|
+
| Field | Type | Default | Description |
|
|
112
|
+
|---|---|---|---|
|
|
113
|
+
| `branding.title` | string | — | Chat header title |
|
|
114
|
+
| `branding.subtitle` | string | — | Chat header subtitle |
|
|
115
|
+
| `branding.theme.primaryColor` | string | `#4F46E5` | Header, buttons, user bubble color |
|
|
116
|
+
| `branding.theme.backgroundColor` | string | `#FFFFFF` | Chat window background |
|
|
117
|
+
| `branding.theme.userBubbleColor` | string | `#4F46E5` | User message bubble color |
|
|
118
|
+
| `branding.theme.botBubbleColor` | string | `#F3F4F6` | Bot message bubble color |
|
|
119
|
+
| `branding.theme.textColor` | string | `#111827` | Main text color |
|
|
120
|
+
| `branding.theme.fontFamily` | string | `Inter, sans-serif` | Font stack |
|
|
121
|
+
| `n8n.webhookUrl` | string | — | Your n8n POST webhook URL |
|
|
122
|
+
| `n8n.timeoutMs` | number | `55000` | n8n request timeout in milliseconds |
|
|
123
|
+
| `chat.welcomeMessage` | string | — | First message shown when chat opens |
|
|
124
|
+
| `chat.fallbackMessage` | string | — | Shown when an error occurs |
|
|
125
|
+
| `chat.matchThreshold` | number | `0.4` | Fuzzy match sensitivity (0–1). Lower = stricter |
|
|
126
|
+
| `chat.showPreQuestionsOnStart` | boolean | `true` | Show FAQ buttons when chat opens |
|
|
127
|
+
| `chat.language` | `"en"` \| `"tl"` | `"en"` | Language for displaying FAQ questions |
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 6. Build the FAQ Tree
|
|
132
|
+
|
|
133
|
+
Edit `questions.json` to define your FAQ categories and answers. The structure supports two levels: main questions and subquestions.
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
[
|
|
137
|
+
{
|
|
138
|
+
"id": "q1",
|
|
139
|
+
"question": "About Our Company",
|
|
140
|
+
"answer": "We are a company that...",
|
|
141
|
+
"subquestions": [
|
|
142
|
+
{
|
|
143
|
+
"id": "q1a",
|
|
144
|
+
"question": "When was the company founded?",
|
|
145
|
+
"answer": "We were founded in 2010.",
|
|
146
|
+
"subquestions": []
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"id": "q1b",
|
|
150
|
+
"question": "What is your mission?",
|
|
151
|
+
"answer": "Our mission is to...",
|
|
152
|
+
"subquestions": []
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"id": "q2",
|
|
158
|
+
"question": "Contact Information",
|
|
159
|
+
"answer": "You can reach us at support@example.com.",
|
|
160
|
+
"subquestions": []
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Rules
|
|
166
|
+
|
|
167
|
+
- Every question must have a unique `id`
|
|
168
|
+
- `subquestions` must be an array (use `[]` if none)
|
|
169
|
+
- `answer` is shown when the question is clicked directly or matched via text search
|
|
170
|
+
- For Tagalog support, mirror the same structure in `questions.tl.json` with translated text — keep the same `id` values
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## 6. Start the Server
|
|
175
|
+
|
|
176
|
+
Create a server entry file (e.g. `server.js` or `server.ts`):
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
import { createServer } from 'rushchatbot/server'
|
|
180
|
+
import path from 'path'
|
|
181
|
+
|
|
182
|
+
createServer({
|
|
183
|
+
configPath: path.resolve('./chatbot/chatbot.config.json'),
|
|
184
|
+
questionsPath: path.resolve('./chatbot/questions.json'),
|
|
185
|
+
questionsTagalogPath: path.resolve('./chatbot/questions.tl.json'), // optional
|
|
186
|
+
port: 3001,
|
|
187
|
+
corsOrigin: 'https://your-frontend-domain.com', // or '*' for development
|
|
188
|
+
}).listen()
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Server options
|
|
192
|
+
|
|
193
|
+
| Option | Type | Default | Description |
|
|
194
|
+
|---|---|---|---|
|
|
195
|
+
| `configPath` | string | — | **Required.** Absolute path to `chatbot.config.json` |
|
|
196
|
+
| `questionsPath` | string | — | **Required.** Absolute path to `questions.json` |
|
|
197
|
+
| `questionsTagalogPath` | string | — | Optional. Absolute path to `questions.tl.json` |
|
|
198
|
+
| `port` | number | `3001` | Port to listen on |
|
|
199
|
+
| `corsOrigin` | string \| string[] | `*` | Allowed CORS origin(s) |
|
|
200
|
+
|
|
201
|
+
Start the server:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
node server.js
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
On successful startup you will see:
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
[RushChatbot] Server running on http://localhost:3001
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## 7. Embed the Widget
|
|
216
|
+
|
|
217
|
+
### React
|
|
218
|
+
|
|
219
|
+
Install peer dependencies if not already present:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
npm install react react-dom marked
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Import and render the widget:
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
import { ChatWidget } from 'rushchatbot/client'
|
|
229
|
+
|
|
230
|
+
export default function App() {
|
|
231
|
+
return (
|
|
232
|
+
<div>
|
|
233
|
+
<ChatWidget apiBase="http://localhost:3001/api/chat" />
|
|
234
|
+
</div>
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
The widget renders as a **floating draggable button** fixed to the bottom-right of the screen. Clicking it opens the chat box above the button.
|
|
240
|
+
|
|
241
|
+
### Widget props
|
|
242
|
+
|
|
243
|
+
| Prop | Type | Default | Description |
|
|
244
|
+
|---|---|---|---|
|
|
245
|
+
| `apiBase` | string | `http://localhost:3001/api/chat` | Base URL of the RushChatbot server |
|
|
246
|
+
| `width` | number | `380` | Chat box width in pixels |
|
|
247
|
+
| `height` | number | `580` | Chat box height in pixels |
|
|
248
|
+
|
|
249
|
+
### Plain HTML / non-React projects
|
|
250
|
+
|
|
251
|
+
Build the client bundle and include it via a script tag:
|
|
252
|
+
|
|
253
|
+
```html
|
|
254
|
+
<script src="https://unpkg.com/react/umd/react.production.min.js"></script>
|
|
255
|
+
<script src="https://unpkg.com/react-dom/umd/react-dom.production.min.js"></script>
|
|
256
|
+
<script src="/path/to/rushchatbot/dist/client.es.js"></script>
|
|
257
|
+
|
|
258
|
+
<div id="rushchatbot-root"></div>
|
|
259
|
+
<script>
|
|
260
|
+
ReactDOM.createRoot(document.getElementById('rushchatbot-root')).render(
|
|
261
|
+
React.createElement(RushChatbotClient.ChatWidget, {
|
|
262
|
+
apiBase: 'http://localhost:3001/api/chat'
|
|
263
|
+
})
|
|
264
|
+
)
|
|
265
|
+
</script>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## 8. Floating Button Behavior
|
|
271
|
+
|
|
272
|
+
The chat button is draggable across the entire screen:
|
|
273
|
+
|
|
274
|
+
- **Drag** — click and hold, then move to reposition the button anywhere on screen
|
|
275
|
+
- **Click** (no drag) — toggles the chat box open or closed
|
|
276
|
+
- **Chat box position** — always appears directly above the button, clamped to the viewport so it never goes off-screen
|
|
277
|
+
- **Close** — click the ✕ button inside the chat header, or click the floating button again
|
|
278
|
+
- Works on both desktop (mouse) and mobile (touch)
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## 9. n8n Webhook Setup
|
|
283
|
+
|
|
284
|
+
When a user types a query that doesn't match any FAQ answer, RushChatbot forwards it to your n8n webhook.
|
|
285
|
+
|
|
286
|
+
### What RushChatbot sends to n8n
|
|
287
|
+
|
|
288
|
+
```json
|
|
289
|
+
{
|
|
290
|
+
"query": "the user's message",
|
|
291
|
+
"sessionId": "sess_abc123"
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Headers sent:
|
|
296
|
+
|
|
297
|
+
```
|
|
298
|
+
Content-Type: application/json
|
|
299
|
+
x-session-id: sess_abc123
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Setting up the webhook in n8n
|
|
303
|
+
|
|
304
|
+
1. Create a new workflow in n8n
|
|
305
|
+
2. Add a **Webhook** trigger node — set method to `POST`
|
|
306
|
+
3. Copy the webhook URL into `chatbot.config.json` under `n8n.webhookUrl`
|
|
307
|
+
4. Add your AI/logic nodes after the webhook trigger
|
|
308
|
+
5. End with a **Respond to Webhook** node returning one of the supported response formats (see section 11)
|
|
309
|
+
6. Activate the workflow
|
|
310
|
+
|
|
311
|
+
### Session continuity
|
|
312
|
+
|
|
313
|
+
The `sessionId` is generated per browser tab (`sess_` + timestamp + random suffix). Pass it through your n8n workflow to maintain conversation context with your AI agent.
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## 10. n8n Response Formats
|
|
318
|
+
|
|
319
|
+
RushChatbot automatically parses all of the following response shapes from n8n:
|
|
320
|
+
|
|
321
|
+
### Single answer
|
|
322
|
+
|
|
323
|
+
```json
|
|
324
|
+
[{ "output": "Your answer text here" }]
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
```json
|
|
328
|
+
[{ "answer": "Your answer text here" }]
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
```json
|
|
332
|
+
[{ "text": "Your answer text here" }]
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### Multiple bubbles (paragraphs)
|
|
336
|
+
|
|
337
|
+
Return a `paragraphs` array to render each item as a **separate chat bubble** with a short delay between them:
|
|
338
|
+
|
|
339
|
+
```json
|
|
340
|
+
[{
|
|
341
|
+
"paragraphs": [
|
|
342
|
+
"First part of the response.",
|
|
343
|
+
"Second part with **bold** and lists.",
|
|
344
|
+
"Third bubble with a follow-up question."
|
|
345
|
+
]
|
|
346
|
+
}]
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Markdown support
|
|
350
|
+
|
|
351
|
+
All responses are rendered as Markdown. Supported formatting:
|
|
352
|
+
|
|
353
|
+
| Syntax | Renders as |
|
|
354
|
+
|---|---|
|
|
355
|
+
| `**bold**` | **bold** |
|
|
356
|
+
| `# Heading` | Large heading |
|
|
357
|
+
| `- item` | Bullet list |
|
|
358
|
+
| `1. item` | Numbered list |
|
|
359
|
+
| `[link](url)` | Hyperlink |
|
|
360
|
+
| `\n` (newline) | Line break |
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## 11. Environment Variables
|
|
365
|
+
|
|
366
|
+
| Variable | Required | Description |
|
|
367
|
+
|---|---|---|
|
|
368
|
+
| `PORT` | No | Override the server port (default: `3001`) |
|
|
369
|
+
|
|
370
|
+
### Setting the port
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
PORT=4000 node server.js
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
## 12. API Reference
|
|
379
|
+
|
|
380
|
+
All endpoints are mounted under `/api/chat`.
|
|
381
|
+
|
|
382
|
+
### `GET /api/chat/config`
|
|
383
|
+
|
|
384
|
+
Returns branding and chat settings. Safe to call from the frontend — never exposes n8n credentials or license key.
|
|
385
|
+
|
|
386
|
+
**Response:**
|
|
387
|
+
```json
|
|
388
|
+
{
|
|
389
|
+
"branding": { "title": "...", "subtitle": "...", "theme": { } },
|
|
390
|
+
"chat": { "welcomeMessage": "...", "language": "en" }
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
---
|
|
395
|
+
|
|
396
|
+
### `GET /api/chat/questions`
|
|
397
|
+
|
|
398
|
+
Returns the FAQ question tree in the configured language.
|
|
399
|
+
|
|
400
|
+
**Response:**
|
|
401
|
+
```json
|
|
402
|
+
[
|
|
403
|
+
{
|
|
404
|
+
"id": "q1",
|
|
405
|
+
"question": "About Our Company",
|
|
406
|
+
"answer": "...",
|
|
407
|
+
"subquestions": []
|
|
408
|
+
}
|
|
409
|
+
]
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
---
|
|
413
|
+
|
|
414
|
+
### `GET /api/chat/query?query=your+question&sessionId=sess_abc`
|
|
415
|
+
|
|
416
|
+
Forwards the query **directly to n8n**, bypassing FAQ matching. Useful for testing your n8n workflow from the browser.
|
|
417
|
+
|
|
418
|
+
**Query params:**
|
|
419
|
+
|
|
420
|
+
| Param | Required | Description |
|
|
421
|
+
|---|---|---|
|
|
422
|
+
| `query` | Yes | The user's question |
|
|
423
|
+
| `sessionId` | No | Session identifier |
|
|
424
|
+
|
|
425
|
+
**Response:**
|
|
426
|
+
```json
|
|
427
|
+
{ "answer": "...", "source": "n8n" }
|
|
428
|
+
```
|
|
429
|
+
or
|
|
430
|
+
```json
|
|
431
|
+
{ "paragraphs": ["...", "..."], "source": "n8n" }
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
---
|
|
435
|
+
|
|
436
|
+
### `POST /api/chat/query`
|
|
437
|
+
|
|
438
|
+
Main query endpoint. Runs the full pipeline: input validation → guardrails → FAQ matching → n8n fallback.
|
|
439
|
+
|
|
440
|
+
**Request body:**
|
|
441
|
+
```json
|
|
442
|
+
{
|
|
443
|
+
"query": "How do I apply for membership?",
|
|
444
|
+
"sessionId": "sess_abc123"
|
|
445
|
+
}
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
**Response (FAQ match):**
|
|
449
|
+
```json
|
|
450
|
+
{
|
|
451
|
+
"answer": "You can apply by...",
|
|
452
|
+
"source": "config",
|
|
453
|
+
"matchedQuestion": "How do I apply for membership?",
|
|
454
|
+
"matchedKeywords": ["apply", "membership"],
|
|
455
|
+
"score": 87
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
**Response (n8n fallback):**
|
|
460
|
+
```json
|
|
461
|
+
{ "answer": "...", "source": "n8n" }
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
**Response (validation/guardrail blocked):**
|
|
465
|
+
```json
|
|
466
|
+
{ "answer": "Please rephrase your question...", "source": "validation" }
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
---
|
|
470
|
+
|
|
471
|
+
### `POST /api/chat/click`
|
|
472
|
+
|
|
473
|
+
Tracks when a user clicks a pre-built FAQ question.
|
|
474
|
+
|
|
475
|
+
**Request body:**
|
|
476
|
+
```json
|
|
477
|
+
{
|
|
478
|
+
"questionId": "q1a",
|
|
479
|
+
"sessionId": "sess_abc123"
|
|
480
|
+
}
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
**Response:**
|
|
484
|
+
```json
|
|
485
|
+
{ "ok": true }
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
### `GET /api/chat/analytics`
|
|
491
|
+
|
|
492
|
+
Returns the full analytics log.
|
|
493
|
+
|
|
494
|
+
**Response:**
|
|
495
|
+
```json
|
|
496
|
+
[
|
|
497
|
+
{
|
|
498
|
+
"sessionId": "sess_abc123",
|
|
499
|
+
"questionId": "q1a",
|
|
500
|
+
"timestamp": "2025-01-01T10:00:00.000Z",
|
|
501
|
+
"type": "click"
|
|
502
|
+
}
|
|
503
|
+
]
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
**Analytics types:**
|
|
507
|
+
|
|
508
|
+
| Type | Description |
|
|
509
|
+
|---|---|
|
|
510
|
+
| `click` | User clicked a pre-built FAQ question |
|
|
511
|
+
| `match` | User query matched a FAQ answer |
|
|
512
|
+
| `n8n` | Query was forwarded to n8n |
|
|
513
|
+
| `error` | Validation, guardrail, or server error |
|
|
514
|
+
|
|
515
|
+
---
|
|
516
|
+
|
|
517
|
+
## 13. Analytics
|
|
518
|
+
|
|
519
|
+
Analytics are written to `analytics.json` in the same directory as your `chatbot.config.json`. Each entry records:
|
|
520
|
+
|
|
521
|
+
- `sessionId` — browser session (resets on new tab)
|
|
522
|
+
- `questionId` — the matched question ID, or `n8n` / `error` / `guardrail`
|
|
523
|
+
- `timestamp` — ISO 8601 UTC
|
|
524
|
+
- `type` — `click`, `match`, `n8n`, or `error`
|
|
525
|
+
|
|
526
|
+
You can query the log at any time via `GET /api/chat/analytics` or read the file directly.
|
|
527
|
+
|
|
528
|
+
---
|
|
529
|
+
|
|
530
|
+
## 14. Troubleshooting
|
|
531
|
+
|
|
532
|
+
### `[RushChatbot] configPath not found`
|
|
533
|
+
|
|
534
|
+
- Use `path.resolve()` to ensure the path is absolute
|
|
535
|
+
- Verify the file exists at the specified location
|
|
536
|
+
|
|
537
|
+
### Chat widget shows nothing / blank
|
|
538
|
+
|
|
539
|
+
- Check the browser console for CORS errors
|
|
540
|
+
- Ensure `corsOrigin` in `createServer()` includes your frontend's origin
|
|
541
|
+
- Confirm the server is running and reachable at the `apiBase` URL
|
|
542
|
+
|
|
543
|
+
### n8n not responding / timeout
|
|
544
|
+
|
|
545
|
+
- Increase `n8n.timeoutMs` in `chatbot.config.json` (default is 55000ms)
|
|
546
|
+
- Test the webhook directly: `GET http://localhost:3001/api/chat/query?query=hello`
|
|
547
|
+
- Check your n8n workflow is activated (not just saved)
|
|
548
|
+
|
|
549
|
+
### Port already in use
|
|
550
|
+
|
|
551
|
+
```bash
|
|
552
|
+
kill $(lsof -ti :3001)
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
### Queries always fall through to n8n (no FAQ matches)
|
|
556
|
+
|
|
557
|
+
- Lower `chat.matchThreshold` in config (e.g. `0.3`)
|
|
558
|
+
- Ensure your `questions.json` answers contain keywords that appear in user queries
|
|
559
|
+
- Check that question `id` values are unique across the entire tree
|
package/index.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>frontend</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="root"></div>
|
|
11
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|