rushchatbot 1.6.8 → 1.6.9
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 +1 -1
- package/package/INTEGRATION.md +1 -1
- package/package/README.md +1 -1
- package/package/package.json +1 -1
- package/package/src/cli/index.ts +23 -4
- package/package/src/server/index.ts +63 -11
- package/package/src/vanilla/index.ts +142 -50
- package/package.json +1 -1
- package/server/data/analytics.json +6 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# RushChatbot
|
|
2
2
|
|
|
3
|
-
**Version:** 1.6.
|
|
3
|
+
**Version:** 1.6.9
|
|
4
4
|
|
|
5
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 widgets for React, Vue 3, and Vanilla JS.
|
|
6
6
|
|
package/package/INTEGRATION.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# RushChatbot
|
|
2
2
|
|
|
3
|
-
**Version:** 1.6.
|
|
3
|
+
**Version:** 1.6.9
|
|
4
4
|
|
|
5
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 widgets for React, Vue 3, and Vanilla JS.
|
|
6
6
|
|
package/package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# RushChatbot
|
|
2
2
|
|
|
3
|
-
**Version:** 1.6.
|
|
3
|
+
**Version:** 1.6.9
|
|
4
4
|
|
|
5
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 widgets for React, Vue 3, and Vanilla JS.
|
|
6
6
|
|
package/package/package.json
CHANGED
package/package/src/cli/index.ts
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
|
|
5
|
+
function sanitizeLog(value: string): string {
|
|
6
|
+
return value.replace(/[\r\n\t]/g, ' ').slice(0, 500)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function safeResolvePath(inputArg: string): string {
|
|
10
|
+
const resolved = path.resolve(inputArg)
|
|
11
|
+
// Reject paths containing traversal sequences
|
|
12
|
+
if (inputArg.includes('..') || inputArg.includes('\0')) {
|
|
13
|
+
throw new Error(`Path traversal detected: ${sanitizeLog(inputArg)}`)
|
|
14
|
+
}
|
|
15
|
+
return resolved
|
|
16
|
+
}
|
|
17
|
+
|
|
5
18
|
const args = process.argv.slice(2)
|
|
6
19
|
const command = args[0]
|
|
7
20
|
|
|
@@ -48,18 +61,24 @@ const DEFAULT_QUESTIONS = [
|
|
|
48
61
|
|
|
49
62
|
function writeIfNotExists(filePath: string, content: unknown) {
|
|
50
63
|
if (fs.existsSync(filePath)) {
|
|
51
|
-
console.log(` [skip] ${filePath} already exists`)
|
|
64
|
+
console.log(` [skip] ${sanitizeLog(filePath)} already exists`)
|
|
52
65
|
return
|
|
53
66
|
}
|
|
54
67
|
fs.writeFileSync(filePath, JSON.stringify(content, null, 2))
|
|
55
|
-
console.log(` [created] ${filePath}`)
|
|
68
|
+
console.log(` [created] ${sanitizeLog(filePath)}`)
|
|
56
69
|
}
|
|
57
70
|
|
|
58
71
|
if (command === 'init') {
|
|
59
|
-
|
|
72
|
+
let targetDir: string
|
|
73
|
+
try {
|
|
74
|
+
targetDir = args[1] ? safeResolvePath(args[1]) : process.cwd()
|
|
75
|
+
} catch (e) {
|
|
76
|
+
console.error(sanitizeLog((e as Error).message))
|
|
77
|
+
process.exit(1)
|
|
78
|
+
}
|
|
60
79
|
fs.mkdirSync(targetDir, { recursive: true })
|
|
61
80
|
|
|
62
|
-
console.log(`\nInitializing RushChatbot config in: ${targetDir}\n`)
|
|
81
|
+
console.log(`\nInitializing RushChatbot config in: ${sanitizeLog(targetDir)}\n`)
|
|
63
82
|
writeIfNotExists(path.join(targetDir, 'chatbot.config.json'), DEFAULT_CONFIG)
|
|
64
83
|
writeIfNotExists(path.join(targetDir, 'questions.json'), DEFAULT_QUESTIONS)
|
|
65
84
|
writeIfNotExists(path.join(targetDir, 'questions.tl.json'), DEFAULT_QUESTIONS)
|
|
@@ -3,10 +3,50 @@ import cors from 'cors'
|
|
|
3
3
|
import axios from 'axios'
|
|
4
4
|
import fs from 'fs'
|
|
5
5
|
import path from 'path'
|
|
6
|
+
import crypto from 'crypto'
|
|
6
7
|
import { findMatch, MatchResult, Question } from './matcher'
|
|
7
8
|
import { checkGuardrails, validateInput } from './guardrails'
|
|
8
9
|
import type { ChatbotConfig } from '../shared/types'
|
|
9
10
|
|
|
11
|
+
function sanitizeLog(value: string): string {
|
|
12
|
+
return value.replace(/[\r\n\t]/g, ' ').slice(0, 500)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function validatePath(inputPath: string, allowedBase: string): string {
|
|
16
|
+
const resolved = path.resolve(inputPath)
|
|
17
|
+
if (!resolved.startsWith(path.resolve(allowedBase) + path.sep) && resolved !== path.resolve(allowedBase)) {
|
|
18
|
+
throw new Error(`[RushChatbot] Path outside allowed directory: ${resolved}`)
|
|
19
|
+
}
|
|
20
|
+
return resolved
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const csrfTokens = new Map<string, number>()
|
|
24
|
+
|
|
25
|
+
function generateCsrfToken(): string {
|
|
26
|
+
const token = crypto.randomBytes(32).toString('hex')
|
|
27
|
+
csrfTokens.set(token, Date.now())
|
|
28
|
+
return token
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function validateCsrfToken(token: string | undefined): boolean {
|
|
32
|
+
if (!token || !csrfTokens.has(token)) return false
|
|
33
|
+
const age = Date.now() - (csrfTokens.get(token) ?? 0)
|
|
34
|
+
if (age > 3600000) { csrfTokens.delete(token); return false }
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function csrfMiddleware(req: express.Request, res: express.Response, next: express.NextFunction) {
|
|
39
|
+
const origin = req.headers.origin
|
|
40
|
+
const referer = req.headers.referer
|
|
41
|
+
// Allow requests with no origin (server-to-server, curl, mobile apps)
|
|
42
|
+
if (!origin && !referer) return next()
|
|
43
|
+
const token = req.headers['x-csrf-token'] as string | undefined
|
|
44
|
+
if (!validateCsrfToken(token)) {
|
|
45
|
+
return res.status(403).json({ error: 'Invalid or missing CSRF token' })
|
|
46
|
+
}
|
|
47
|
+
next()
|
|
48
|
+
}
|
|
49
|
+
|
|
10
50
|
export interface RushChatbotServerOptions {
|
|
11
51
|
/** Absolute path to your chatbot.config.json */
|
|
12
52
|
configPath: string
|
|
@@ -63,30 +103,31 @@ export function createServer(options: RushChatbotServerOptions) {
|
|
|
63
103
|
if (!fs.existsSync(configPath)) throw new Error(`[RushChatbot] configPath not found: ${configPath}`)
|
|
64
104
|
if (!fs.existsSync(questionsPath)) throw new Error(`[RushChatbot] questionsPath not found: ${questionsPath}`)
|
|
65
105
|
|
|
66
|
-
const
|
|
106
|
+
const allowedBase = path.dirname(path.resolve(configPath))
|
|
107
|
+
const analyticsPath = path.join(allowedBase, 'analytics.json')
|
|
67
108
|
|
|
68
109
|
function getConfig(): ChatbotConfig {
|
|
69
|
-
return JSON.parse(fs.readFileSync(configPath, 'utf-8'))
|
|
110
|
+
return JSON.parse(fs.readFileSync(validatePath(configPath, allowedBase), 'utf-8'))
|
|
70
111
|
}
|
|
71
112
|
|
|
72
113
|
function getQuestions(lang: 'en' | 'tl'): Question[] {
|
|
73
114
|
if (lang === 'tl') {
|
|
74
115
|
if (!questionsTagalogPath || !fs.existsSync(questionsTagalogPath)) return []
|
|
75
|
-
return JSON.parse(fs.readFileSync(questionsTagalogPath, 'utf-8'))
|
|
116
|
+
return JSON.parse(fs.readFileSync(validatePath(questionsTagalogPath, allowedBase), 'utf-8'))
|
|
76
117
|
}
|
|
77
|
-
return JSON.parse(fs.readFileSync(questionsPath, 'utf-8'))
|
|
118
|
+
return JSON.parse(fs.readFileSync(validatePath(questionsPath, allowedBase), 'utf-8'))
|
|
78
119
|
}
|
|
79
120
|
|
|
80
121
|
function getAnalytics(): AnalyticsEntry[] {
|
|
81
122
|
if (!fs.existsSync(analyticsPath)) return []
|
|
82
|
-
return JSON.parse(fs.readFileSync(analyticsPath, 'utf-8'))
|
|
123
|
+
return JSON.parse(fs.readFileSync(validatePath(analyticsPath, allowedBase), 'utf-8'))
|
|
83
124
|
}
|
|
84
125
|
|
|
85
126
|
function saveAnalytics(entry: AnalyticsEntry) {
|
|
86
127
|
try {
|
|
87
128
|
const analytics = getAnalytics()
|
|
88
129
|
analytics.push(entry)
|
|
89
|
-
fs.writeFileSync(analyticsPath, JSON.stringify(analytics, null, 2))
|
|
130
|
+
fs.writeFileSync(validatePath(analyticsPath, allowedBase), JSON.stringify(analytics, null, 2))
|
|
90
131
|
} catch (e) {
|
|
91
132
|
console.error('[RushChatbot analytics error]', e)
|
|
92
133
|
}
|
|
@@ -99,10 +140,21 @@ export function createServer(options: RushChatbotServerOptions) {
|
|
|
99
140
|
const app = express()
|
|
100
141
|
app.use(cors({ origin: corsOrigin }))
|
|
101
142
|
app.use(express.json())
|
|
143
|
+
// Apply CSRF protection globally to all state-changing methods
|
|
144
|
+
app.use((req, res, next) => {
|
|
145
|
+
if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(req.method)) {
|
|
146
|
+
return csrfMiddleware(req, res, next)
|
|
147
|
+
}
|
|
148
|
+
next()
|
|
149
|
+
})
|
|
102
150
|
|
|
103
151
|
const router = express.Router()
|
|
104
152
|
|
|
105
|
-
router.
|
|
153
|
+
router.get('/csrf-token', (_req, res) => {
|
|
154
|
+
res.json({ csrfToken: generateCsrfToken() })
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
router.post('/click', csrfMiddleware, (req, res) => {
|
|
106
158
|
const { questionId } = req.body
|
|
107
159
|
const sid = getSid(req)
|
|
108
160
|
if (!questionId || typeof questionId !== 'string')
|
|
@@ -126,12 +178,12 @@ export function createServer(options: RushChatbotServerOptions) {
|
|
|
126
178
|
return res.json({ ...parseN8nResponse(data), source: 'n8n' })
|
|
127
179
|
} catch (err: unknown) {
|
|
128
180
|
const message = err instanceof Error ? err.message : String(err)
|
|
129
|
-
console.error('[RushChatbot query GET error]', message)
|
|
130
|
-
return res.status(500).json({ error:
|
|
181
|
+
console.error('[RushChatbot query GET error]', sanitizeLog(message))
|
|
182
|
+
return res.status(500).json({ error: 'Internal server error' })
|
|
131
183
|
}
|
|
132
184
|
})
|
|
133
185
|
|
|
134
|
-
router.post('/query', async (req, res) => {
|
|
186
|
+
router.post('/query', csrfMiddleware, async (req, res) => {
|
|
135
187
|
const sid = getSid(req)
|
|
136
188
|
const cfg = getConfig()
|
|
137
189
|
try {
|
|
@@ -181,7 +233,7 @@ export function createServer(options: RushChatbotServerOptions) {
|
|
|
181
233
|
|
|
182
234
|
} catch (err: unknown) {
|
|
183
235
|
const message = err instanceof Error ? err.message : String(err)
|
|
184
|
-
console.error('[RushChatbot query error]', message)
|
|
236
|
+
console.error('[RushChatbot query error]', sanitizeLog(message))
|
|
185
237
|
saveAnalytics({ sessionId: sid, questionId: 'error', timestamp: new Date().toISOString(), type: 'error' })
|
|
186
238
|
return res.status(500).json({ answer: cfg.chat.fallbackMessage, source: 'error' })
|
|
187
239
|
}
|
|
@@ -2,6 +2,15 @@ import { RushChatbot, parseMarkdown } from '../core/RushChatbot'
|
|
|
2
2
|
import type { RushChatbotState, WidgetSettings } from '../core/RushChatbot'
|
|
3
3
|
import type { Question, Message } from '../shared/types'
|
|
4
4
|
|
|
5
|
+
function escapeHtml(str: string): string {
|
|
6
|
+
return str
|
|
7
|
+
.replace(/&/g, '&')
|
|
8
|
+
.replace(/</g, '<')
|
|
9
|
+
.replace(/>/g, '>')
|
|
10
|
+
.replace(/"/g, '"')
|
|
11
|
+
.replace(/'/g, ''')
|
|
12
|
+
}
|
|
13
|
+
|
|
5
14
|
const STYLES = `
|
|
6
15
|
@keyframes rushchatbot-bounce {
|
|
7
16
|
0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
|
|
@@ -137,42 +146,100 @@ class RushChatbotElement extends HTMLElement {
|
|
|
137
146
|
const msgsEl = this.shadow.querySelector('.messages') as HTMLElement | null
|
|
138
147
|
const wasAtBottom = msgsEl ? msgsEl.scrollHeight - msgsEl.scrollTop - msgsEl.clientHeight < 60 : true
|
|
139
148
|
|
|
140
|
-
|
|
149
|
+
// Build static shell with no user data in innerHTML
|
|
150
|
+
const shellHtml = `
|
|
141
151
|
<style>${STYLES}</style>
|
|
142
|
-
<div class="container"
|
|
143
|
-
<div class="header"
|
|
144
|
-
<div class="header-title"
|
|
145
|
-
<div class="header-subtitle"
|
|
152
|
+
<div class="container" id="container">
|
|
153
|
+
<div class="header" id="header">
|
|
154
|
+
<div class="header-title" id="header-title"></div>
|
|
155
|
+
<div class="header-subtitle" id="header-subtitle"></div>
|
|
146
156
|
</div>
|
|
147
157
|
<div class="messages-wrap">
|
|
148
|
-
${this.showScrollBtn ? `
|
|
149
|
-
<button class="scroll-btn" id="scrollBtn" style="background:${theme.primaryColor}" aria-label="Scroll to latest">
|
|
150
|
-
<svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M8 3v10M3 9l5 5 5-5" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
|
151
|
-
</button>` : ''}
|
|
152
158
|
<div class="messages" id="msgs">
|
|
153
|
-
|
|
154
|
-
${state.loading ? `<div class="thinking" style="background:${theme.botBubbleColor}">
|
|
155
|
-
${[0,1,2].map(i => `<span class="dot" style="background:${theme.primaryColor};animation:rushchatbot-bounce 1.2s ease-in-out ${i*0.2}s infinite"></span>`).join('')}
|
|
156
|
-
</div>` : ''}
|
|
157
|
-
${state.showMain && state.questions.length > 0 ? `
|
|
158
|
-
<div class="main-list">
|
|
159
|
-
${state.questions.map(q => `
|
|
160
|
-
<button class="main-btn" data-action="main" data-id="${q.id}"
|
|
161
|
-
style="border:1px solid ${theme.primaryColor};color:${theme.primaryColor}">
|
|
162
|
-
${q.question}
|
|
163
|
-
</button>`).join('')}
|
|
164
|
-
${settings.hideEndChat ? '' : `<button class="end-btn" data-action="endchat">👋 I'm done, thanks!</button>`}
|
|
165
|
-
</div>` : ''}
|
|
159
|
+
<div id="msgs-content"></div>
|
|
166
160
|
<div id="bottom"></div>
|
|
167
161
|
</div>
|
|
168
162
|
</div>
|
|
169
163
|
${settings.hideInput ? '' : `
|
|
170
164
|
<form class="input-row" id="form">
|
|
171
|
-
<input id="input"
|
|
172
|
-
<button type="submit"
|
|
165
|
+
<input id="input" />
|
|
166
|
+
<button type="submit" id="send-btn"></button>
|
|
173
167
|
</form>`}
|
|
174
168
|
</div>
|
|
175
169
|
`
|
|
170
|
+
this.shadow.innerHTML = shellHtml
|
|
171
|
+
|
|
172
|
+
// Populate dynamic values via DOM (safe from XSS)
|
|
173
|
+
const container = this.shadow.getElementById('container') as HTMLElement
|
|
174
|
+
container.style.cssText = `background:${escapeHtml(theme.backgroundColor)};color:${escapeHtml(theme.textColor)};width:${this.w};height:${this.h};font-family:${escapeHtml(theme.fontFamily)};border-radius:${borderRadius}px;box-shadow:${shadow}`
|
|
175
|
+
|
|
176
|
+
const header = this.shadow.getElementById('header') as HTMLElement
|
|
177
|
+
header.style.background = escapeHtml(theme.primaryColor)
|
|
178
|
+
;(this.shadow.getElementById('header-title') as HTMLElement).textContent = state.config!.branding.title
|
|
179
|
+
;(this.shadow.getElementById('header-subtitle') as HTMLElement).textContent = state.config!.branding.subtitle
|
|
180
|
+
|
|
181
|
+
const msgsContent = this.shadow.getElementById('msgs-content') as HTMLElement
|
|
182
|
+
msgsContent.textContent = ''
|
|
183
|
+
|
|
184
|
+
state.messages.forEach((msg, idx) => {
|
|
185
|
+
msgsContent.appendChild(this.renderMsg(msg, idx))
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
if (state.loading) {
|
|
189
|
+
const thinking = document.createElement('div')
|
|
190
|
+
thinking.className = 'thinking'
|
|
191
|
+
thinking.style.background = escapeHtml(theme.botBubbleColor)
|
|
192
|
+
;[0,1,2].forEach(i => {
|
|
193
|
+
const dot = document.createElement('span')
|
|
194
|
+
dot.className = 'dot'
|
|
195
|
+
dot.style.cssText = `background:${escapeHtml(theme.primaryColor)};animation:rushchatbot-bounce 1.2s ease-in-out ${i*0.2}s infinite`
|
|
196
|
+
thinking.appendChild(dot)
|
|
197
|
+
})
|
|
198
|
+
msgsContent.appendChild(thinking)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (state.showMain && state.questions.length > 0) {
|
|
202
|
+
const mainList = document.createElement('div')
|
|
203
|
+
mainList.className = 'main-list'
|
|
204
|
+
state.questions.forEach(q => {
|
|
205
|
+
const btn = document.createElement('button')
|
|
206
|
+
btn.className = 'main-btn'
|
|
207
|
+
btn.dataset.action = 'main'
|
|
208
|
+
btn.dataset.id = q.id
|
|
209
|
+
btn.style.cssText = `border:1px solid ${escapeHtml(theme.primaryColor)};color:${escapeHtml(theme.primaryColor)}`
|
|
210
|
+
btn.textContent = q.question
|
|
211
|
+
mainList.appendChild(btn)
|
|
212
|
+
})
|
|
213
|
+
if (!settings.hideEndChat) {
|
|
214
|
+
const endBtn = document.createElement('button')
|
|
215
|
+
endBtn.className = 'end-btn'
|
|
216
|
+
endBtn.dataset.action = 'endchat'
|
|
217
|
+
endBtn.textContent = "\uD83D\uDC4B I'm done, thanks!"
|
|
218
|
+
mainList.appendChild(endBtn)
|
|
219
|
+
}
|
|
220
|
+
msgsContent.appendChild(mainList)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (this.showScrollBtn) {
|
|
224
|
+
const scrollBtn = document.createElement('button')
|
|
225
|
+
scrollBtn.className = 'scroll-btn'
|
|
226
|
+
scrollBtn.id = 'scrollBtn'
|
|
227
|
+
scrollBtn.style.background = escapeHtml(theme.primaryColor)
|
|
228
|
+
scrollBtn.setAttribute('aria-label', 'Scroll to latest')
|
|
229
|
+
scrollBtn.innerHTML = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M8 3v10M3 9l5 5 5-5" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>`
|
|
230
|
+
this.shadow.querySelector('.messages-wrap')!.prepend(scrollBtn)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (!settings.hideInput) {
|
|
234
|
+
const inputEl = this.shadow.getElementById('input') as HTMLInputElement
|
|
235
|
+
inputEl.placeholder = placeholder
|
|
236
|
+
inputEl.value = state.input
|
|
237
|
+
if (state.loading) inputEl.disabled = true
|
|
238
|
+
const sendBtn = this.shadow.getElementById('send-btn') as HTMLButtonElement
|
|
239
|
+
sendBtn.textContent = sendLabel
|
|
240
|
+
sendBtn.style.background = escapeHtml(theme.primaryColor)
|
|
241
|
+
if (state.loading) sendBtn.disabled = true
|
|
242
|
+
}
|
|
176
243
|
|
|
177
244
|
const newMsgsEl = this.shadow.getElementById('msgs') as HTMLElement
|
|
178
245
|
if (wasAtBottom) {
|
|
@@ -257,41 +324,66 @@ class RushChatbotElement extends HTMLElement {
|
|
|
257
324
|
})
|
|
258
325
|
}
|
|
259
326
|
|
|
260
|
-
private renderMsg(msg: Message, idx: number):
|
|
327
|
+
private renderMsg(msg: Message, idx: number): HTMLElement {
|
|
261
328
|
const { theme } = this
|
|
262
329
|
const isUser = msg.role === 'user'
|
|
263
330
|
const bgColor = isUser ? theme.userBubbleColor : theme.botBubbleColor
|
|
264
331
|
const color = isUser ? '#fff' : theme.textColor
|
|
265
|
-
|
|
332
|
+
|
|
333
|
+
const row = document.createElement('div')
|
|
334
|
+
row.className = `msg-row ${isUser ? 'user' : 'bot'}`
|
|
335
|
+
if (idx === 0) row.style.marginTop = '48px'
|
|
336
|
+
|
|
337
|
+
const bubble = document.createElement('div')
|
|
338
|
+
bubble.className = 'bubble'
|
|
339
|
+
bubble.style.cssText = `background:${escapeHtml(bgColor)};color:${escapeHtml(color)}`
|
|
266
340
|
|
|
267
341
|
if (msg.subquestions && msg.subquestions.length > 0) {
|
|
268
342
|
const siblingIds = msg.subquestions.map((s: Question) => s.id).join(',')
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
343
|
+
const mdDiv = document.createElement('div')
|
|
344
|
+
mdDiv.className = 'rushchatbot-md'
|
|
345
|
+
mdDiv.style.marginBottom = '8px'
|
|
346
|
+
mdDiv.innerHTML = parseMarkdown(msg.text)
|
|
347
|
+
bubble.appendChild(mdDiv)
|
|
348
|
+
|
|
349
|
+
const subList = document.createElement('div')
|
|
350
|
+
subList.className = 'sub-list'
|
|
351
|
+
msg.subquestions.forEach((sub: Question) => {
|
|
352
|
+
const btn = document.createElement('button')
|
|
353
|
+
btn.className = 'btn'
|
|
354
|
+
btn.dataset.action = 'sub'
|
|
355
|
+
btn.dataset.id = sub.id
|
|
356
|
+
btn.dataset.siblings = siblingIds
|
|
357
|
+
btn.style.cssText = `border:1px solid ${escapeHtml(theme.primaryColor)};color:${escapeHtml(theme.primaryColor)}`
|
|
358
|
+
btn.textContent = sub.question
|
|
359
|
+
subList.appendChild(btn)
|
|
360
|
+
})
|
|
361
|
+
const backBtn = document.createElement('button')
|
|
362
|
+
backBtn.className = 'btn'
|
|
363
|
+
backBtn.dataset.action = 'back'
|
|
364
|
+
backBtn.style.cssText = 'border:1px solid #6B7280;color:#6B7280'
|
|
365
|
+
backBtn.textContent = '\u2190 Back to main menu'
|
|
366
|
+
subList.appendChild(backBtn)
|
|
367
|
+
bubble.appendChild(subList)
|
|
368
|
+
} else if (isUser) {
|
|
369
|
+
bubble.textContent = msg.text
|
|
370
|
+
} else {
|
|
371
|
+
const mdDiv = document.createElement('div')
|
|
372
|
+
mdDiv.className = 'rushchatbot-md'
|
|
373
|
+
mdDiv.innerHTML = parseMarkdown(msg.text)
|
|
374
|
+
bubble.appendChild(mdDiv)
|
|
375
|
+
if (msg.isEndChat) {
|
|
376
|
+
const newChatBtn = document.createElement('button')
|
|
377
|
+
newChatBtn.className = 'new-chat-btn'
|
|
378
|
+
newChatBtn.dataset.action = 'newchat'
|
|
379
|
+
newChatBtn.style.background = escapeHtml(theme.primaryColor)
|
|
380
|
+
newChatBtn.textContent = '\uD83D\uDD04 Start a new chat'
|
|
381
|
+
bubble.appendChild(newChatBtn)
|
|
382
|
+
}
|
|
283
383
|
}
|
|
284
384
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
<div class="bubble" style="background:${bgColor};color:${color}">
|
|
288
|
-
${isUser
|
|
289
|
-
? msg.text
|
|
290
|
-
: `<div class="rushchatbot-md">${parseMarkdown(msg.text)}</div>
|
|
291
|
-
${msg.isEndChat ? `<button class="new-chat-btn" data-action="newchat" style="background:${theme.primaryColor}">🔄 Start a new chat</button>` : ''}`
|
|
292
|
-
}
|
|
293
|
-
</div>
|
|
294
|
-
</div>`
|
|
385
|
+
row.appendChild(bubble)
|
|
386
|
+
return row
|
|
295
387
|
}
|
|
296
388
|
}
|
|
297
389
|
|
package/package.json
CHANGED