domma-cms 1.49.2 → 1.50.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/CHANGELOG.md +7 -0
- package/admin/js/lib/chats-arrange.js +2 -2
- package/admin/js/lib/launchers-arrange.js +5 -2
- package/admin/js/lib/site-settings-arrange.js +2 -2
- package/admin/js/templates/chats.html +26 -2
- package/admin/js/templates/docs/usage-chat.html +51 -5
- package/admin/js/templates/launchers.html +4 -0
- package/admin/js/templates/settings.html +18 -0
- package/admin/js/views/chats.js +5 -5
- package/admin/js/views/launchers.js +105 -33
- package/docs/DommaFeatures.md +4 -0
- package/package.json +1 -1
- package/public/css/launcher-chat.css +1 -1
- package/public/css/launchers.css +1 -1
- package/public/js/launcher-chat.mjs +16 -10
- package/public/js/launcher-settings.mjs +6 -2
- package/public/js/launchers.mjs +3 -3
- package/server/routes/api/chat.js +4 -2
- package/server/routes/api/chats.js +37 -0
- package/server/routes/api/settings.js +11 -1
- package/server/services/assistant.js +67 -0
- package/server/services/chat/ai.js +109 -0
- package/server/services/chat/conversation.js +37 -2
- package/server/services/chat/saved.js +117 -0
- package/server/services/chat/settings.js +30 -4
- package/server/services/chat/store.js +1 -1
- package/server/services/collectionAccess.js +2 -1
- package/server/services/launchers.js +1 -1
- package/server/services/presetCollections.js +24 -2
- package/server/services/siteGitignore.js +1 -1
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
patchSession, removeSession, removeSessionsAndOrphans, renderAnswer, staffAvailable, withChat
|
|
28
28
|
} from './store.js';
|
|
29
29
|
import {readChatSettings, staffDisplayName} from './settings.js';
|
|
30
|
+
import {aiAnswer} from './ai.js';
|
|
30
31
|
|
|
31
32
|
export const SOURCE = 'core:chat';
|
|
32
33
|
const int = (v) => (Number.isFinite(Number(v)) ? Math.trunc(Number(v)) : 0);
|
|
@@ -100,6 +101,7 @@ export function publicMessage(m, chat, knowledge = new Map()) {
|
|
|
100
101
|
out.text = String(d.text || '');
|
|
101
102
|
}
|
|
102
103
|
if (d.from === 'bot') out.name = chat.botName;
|
|
104
|
+
if (d.from === 'bot' && (d.ai === true || d.ai === 'true')) out.ai = true;
|
|
103
105
|
if (d.from === 'staff') out.name = d.staffName || 'The team';
|
|
104
106
|
if (d.from === 'bot' && Array.isArray(d.suggestions) && d.suggestions.length) {
|
|
105
107
|
out.suggestions = d.suggestions.map((s, i) => ({label: String(s?.label || ''), i}));
|
|
@@ -139,6 +141,7 @@ export function staffMessage(m, knowledge = new Map()) {
|
|
|
139
141
|
return {
|
|
140
142
|
n: int(d.n), from: d.from, text: String(d.text || ''), at: m.meta?.createdAt || null,
|
|
141
143
|
name: d.staffName || '', answer: d.answerId ? (knowledge.get(d.answerId)?.question || '(an entry since removed)') : '',
|
|
144
|
+
ai: d.ai === true || d.ai === 'true',
|
|
142
145
|
suggestions: Array.isArray(d.suggestions) ? d.suggestions.map(s => String(s?.label || '')) : []
|
|
143
146
|
};
|
|
144
147
|
}
|
|
@@ -157,6 +160,18 @@ export function needsStaff(data) {
|
|
|
157
160
|
// The bot
|
|
158
161
|
// ---------------------------------------------------------------------------
|
|
159
162
|
|
|
163
|
+
/**
|
|
164
|
+
* An AI answer written to the chat, or null: AI off for this launcher, this chat's allowance used
|
|
165
|
+
* (`aiMaxPerChat`), or nothing to say. Inside withChat.
|
|
166
|
+
*/
|
|
167
|
+
async function aiTurn(id, text, chat, session) {
|
|
168
|
+
if (!chat.ai) return null;
|
|
169
|
+
const used = int(session?.data.aiCount);
|
|
170
|
+
if (used >= int(chat.aiMaxPerChat ?? 20)) return null;
|
|
171
|
+
const said = await aiAnswer(id, text, chat);
|
|
172
|
+
return said ? addMessage(id, {from: 'bot', text: said, ai: true}, {misses: 0, aiCount: used + 1}) : null;
|
|
173
|
+
}
|
|
174
|
+
|
|
160
175
|
/** The bot's reply to a visitor's words, written to the chat. Inside withChat. */
|
|
161
176
|
async function botReply(id, text, chat, settings) {
|
|
162
177
|
const {index, byId} = await knowledgeIndex();
|
|
@@ -170,10 +185,16 @@ async function botReply(id, text, chat, settings) {
|
|
|
170
185
|
return addMessage(id, {from: 'bot', text: byId.get(r.best.id)?.answer || '', answerId: r.best.id}, {misses: 0});
|
|
171
186
|
}
|
|
172
187
|
if (r.kind === 'suggest') {
|
|
188
|
+
// A near miss: the AI (which sees the whole Knowledge) answers it if it can; the choices are the fallback.
|
|
189
|
+
const said = await aiTurn(id, text, chat, session);
|
|
190
|
+
if (said) return said;
|
|
173
191
|
return addMessage(id, {from: 'bot', text: SAY.suggest,
|
|
174
192
|
suggestions: r.suggestions.map(s => ({id: s.id, label: s.question}))});
|
|
175
193
|
}
|
|
194
|
+
// Still logged when the AI answers: it is a gap in the Knowledge worth filling either way.
|
|
176
195
|
await logUnanswered(text, r.best?.question || '');
|
|
196
|
+
const said = await aiTurn(id, text, chat, session);
|
|
197
|
+
if (said) return said;
|
|
177
198
|
const misses = int(session?.data.misses) + 1;
|
|
178
199
|
const out = await addMessage(id, {from: 'bot', text: chat.staff ? SAY.noneStaff : SAY.noneAlone}, {misses});
|
|
179
200
|
if (chat.staff && misses >= 2) return addMessage(id, {from: 'bot', text: SAY.offerPerson});
|
|
@@ -416,8 +437,10 @@ export function staffDeletes(id) {
|
|
|
416
437
|
*/
|
|
417
438
|
export const BOT_ONLY_DAYS = 7;
|
|
418
439
|
|
|
419
|
-
export async function sweepChats({at = Date.now(), retentionDays = readChatSettings().retentionDays} = {}) {
|
|
440
|
+
export async function sweepChats({at = Date.now(), retentionDays = readChatSettings().retentionDays, keepFor = null} = {}) {
|
|
420
441
|
const HOUR = 3_600_000;
|
|
442
|
+
// A chat launcher may keep its own chats for longer or shorter than the site (chat.keepDays; 0 = the site's).
|
|
443
|
+
const perLauncher = keepFor || await launcherKeepDays();
|
|
421
444
|
let closed = 0;
|
|
422
445
|
const doomed = [];
|
|
423
446
|
for (const entry of await listSessions()) {
|
|
@@ -435,7 +458,9 @@ export async function sweepChats({at = Date.now(), retentionDays = readChatSetti
|
|
|
435
458
|
forgetSession(entry.id);
|
|
436
459
|
} else if (d.status === 'closed') {
|
|
437
460
|
const botOnly = !d.assignedTo && !d.visitorEmail;
|
|
438
|
-
const
|
|
461
|
+
const own = perLauncher.get(String(d.launcherId || '')) || 0;
|
|
462
|
+
const days = own > 0 ? own : retentionDays;
|
|
463
|
+
const keepDays = botOnly ? Math.min(BOT_ONLY_DAYS, days) : days;
|
|
439
464
|
if (quiet >= keepDays * 24 * HOUR) doomed.push(entry.id);
|
|
440
465
|
else forgetSession(entry.id);
|
|
441
466
|
}
|
|
@@ -444,6 +469,16 @@ export async function sweepChats({at = Date.now(), retentionDays = readChatSetti
|
|
|
444
469
|
return {closed, deleted: removed.chats, messages: removed.messages};
|
|
445
470
|
}
|
|
446
471
|
|
|
472
|
+
/** launcherId -> keepDays (only the launchers that set their own). */
|
|
473
|
+
async function launcherKeepDays() {
|
|
474
|
+
try {
|
|
475
|
+
const {chatLaunchers} = await import('../launchers.js');
|
|
476
|
+
return new Map((await chatLaunchers()).filter(l => Number(l.chat?.keepDays) > 0).map(l => [String(l.id), Number(l.chat.keepDays)]));
|
|
477
|
+
} catch {
|
|
478
|
+
return new Map();
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
447
482
|
let sweepTimer = null;
|
|
448
483
|
|
|
449
484
|
/** Run the tidy-up an hour after start, then hourly. */
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Saved chats - a copy of a visitor chat kept for a closer look (the chat-saved
|
|
3
|
+
* preset). Staff save one from the Chats inbox with a note on why; the copy
|
|
4
|
+
* is the whole conversation as it stood, so it outlives the chat's own
|
|
5
|
+
* retention and its deletion, and carries an outcome staff move along
|
|
6
|
+
* (to look at -> looking into it -> done).
|
|
7
|
+
*
|
|
8
|
+
* @module services/chat/saved
|
|
9
|
+
*/
|
|
10
|
+
import {createEntry, deleteEntry, getEntry, listEntries, updateEntry} from '../collections.js';
|
|
11
|
+
import {cleanText, getSession, knowledgeIndex, messagesAfter} from './store.js';
|
|
12
|
+
import {staffMessage, staffSummary} from './conversation.js';
|
|
13
|
+
|
|
14
|
+
export const SAVED_SLUG = 'chat-saved';
|
|
15
|
+
export const OUTCOMES = Object.freeze(['to look at', 'looking into it', 'done']);
|
|
16
|
+
export const NOTE_MAX = 2000;
|
|
17
|
+
/** Saved chats a site keeps at most: past it, the oldest that are done go first, then saving is refused. */
|
|
18
|
+
export const SAVED_MAX = 2000;
|
|
19
|
+
|
|
20
|
+
const WHO = {visitor: 'Visitor', bot: 'Bot', staff: 'Staff', system: 'Note'};
|
|
21
|
+
|
|
22
|
+
/** The conversation as plain text, one message a paragraph - what the Collections screen shows. */
|
|
23
|
+
export function transcriptOf(messages, chat = {}) {
|
|
24
|
+
return messages.map((m) => {
|
|
25
|
+
const at = m.at ? new Date(m.at).toISOString().slice(0, 16).replace('T', ' ') : '';
|
|
26
|
+
const who = m.from === 'visitor' ? (chat.name || WHO.visitor) : m.from === 'staff' ? (m.name || WHO.staff) : WHO[m.from] || m.from;
|
|
27
|
+
const answer = m.from === 'bot' && m.answer ? ` [Knowledge: ${m.answer}]` : m.from === 'bot' && m.ai ? ' [AI]' : '';
|
|
28
|
+
return `[${at}] ${who}: ${m.text}${answer}`;
|
|
29
|
+
}).join('\n\n');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A short title: who, and what they first asked. */
|
|
33
|
+
export function titleOf(chat) {
|
|
34
|
+
const who = chat.name || 'A visitor';
|
|
35
|
+
const about = chat.summary ? ` - ${chat.summary}` : '';
|
|
36
|
+
return `${who}${about}`.slice(0, 140);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** One saved chat for the inbox list (no messages). */
|
|
40
|
+
export function savedSummary(entry) {
|
|
41
|
+
const d = entry.data || {};
|
|
42
|
+
return {
|
|
43
|
+
id: entry.id, title: d.title || '', note: d.note || '', outcome: OUTCOMES.includes(d.outcome) ? d.outcome : OUTCOMES[0],
|
|
44
|
+
name: d.visitorName || '', email: d.visitorEmail || '', page: d.page || '', chatId: d.chatId || '',
|
|
45
|
+
count: Number(d.messageCount) || 0, startedAt: d.startedAt || null, savedAt: d.savedAt || entry.meta?.createdAt || null,
|
|
46
|
+
savedBy: d.savedByName || '', updatedAt: entry.meta?.updatedAt || null
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** One saved chat with its messages. */
|
|
51
|
+
export function savedDetail(entry) {
|
|
52
|
+
const d = entry.data || {};
|
|
53
|
+
return {...savedSummary(entry), messages: Array.isArray(d.messages) ? d.messages : []};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Save a copy of chat `id`.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} id
|
|
60
|
+
* @param {{note?: string}} body
|
|
61
|
+
* @param {{id?: string, name?: string}} user
|
|
62
|
+
* @returns {Promise<{item?: object, error?: string, code?: number}>}
|
|
63
|
+
*/
|
|
64
|
+
export async function saveChat(id, body = {}, user = {}) {
|
|
65
|
+
const session = await getSession(id, {fresh: true});
|
|
66
|
+
if (!session) return {error: 'Chat not found', code: 404};
|
|
67
|
+
const {total} = await listEntries(SAVED_SLUG, {limit: 1});
|
|
68
|
+
if (total >= SAVED_MAX) return {error: `There are ${SAVED_MAX} saved chats already. Delete some you have finished with first.`, code: 409};
|
|
69
|
+
const {byId} = await knowledgeIndex();
|
|
70
|
+
const messages = (await messagesAfter(id, 0)).map(m => staffMessage(m, byId))
|
|
71
|
+
.map(({n, from, text, at, name, answer, ai}) => ({n, from, text, at, ...(name && {name}), ...(answer && {answer}), ...(ai && {ai: true})}));
|
|
72
|
+
const chat = staffSummary(session);
|
|
73
|
+
const at = new Date().toISOString();
|
|
74
|
+
const entry = await createEntry(SAVED_SLUG, {
|
|
75
|
+
title: titleOf(chat),
|
|
76
|
+
note: cleanText(body.note, NOTE_MAX),
|
|
77
|
+
outcome: OUTCOMES[0],
|
|
78
|
+
chatId: chat.id, launcherId: chat.launcherId, chatStatus: chat.status,
|
|
79
|
+
visitorName: chat.name, visitorEmail: chat.email, page: chat.page,
|
|
80
|
+
startedAt: chat.startedAt, lastAt: chat.lastAt, savedAt: at,
|
|
81
|
+
savedBy: String(user.id || ''), savedByName: String(user.name || '').slice(0, 80),
|
|
82
|
+
messageCount: messages.length,
|
|
83
|
+
transcript: transcriptOf(messages, chat),
|
|
84
|
+
messages
|
|
85
|
+
}, {createdBy: user.id || null, source: 'chat'});
|
|
86
|
+
return {item: savedSummary(entry)};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function listSaved() {
|
|
90
|
+
const {entries} = await listEntries(SAVED_SLUG, {limit: 0, sort: 'savedAt', order: 'desc'});
|
|
91
|
+
return entries.map(savedSummary);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function getSaved(id) {
|
|
95
|
+
const entry = await getEntry(SAVED_SLUG, id);
|
|
96
|
+
return entry ? savedDetail(entry) : null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Staff change the note or move the outcome along. */
|
|
100
|
+
export async function updateSaved(id, body = {}) {
|
|
101
|
+
const entry = await getEntry(SAVED_SLUG, id);
|
|
102
|
+
if (!entry) return {missing: true};
|
|
103
|
+
const patch = {};
|
|
104
|
+
if (body.note !== undefined) patch.note = cleanText(body.note, NOTE_MAX);
|
|
105
|
+
if (body.outcome !== undefined) {
|
|
106
|
+
if (!OUTCOMES.includes(body.outcome)) return {error: 'Pick to look at, looking into it or done.'};
|
|
107
|
+
patch.outcome = body.outcome;
|
|
108
|
+
}
|
|
109
|
+
const updated = await updateEntry(SAVED_SLUG, id, {...entry.data, ...patch});
|
|
110
|
+
return {item: savedSummary(updated)};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function removeSaved(id) {
|
|
114
|
+
if (!await getEntry(SAVED_SLUG, id)) return false;
|
|
115
|
+
await deleteEntry(SAVED_SLUG, id);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import {getConfig, saveConfig} from '../../config.js';
|
|
17
17
|
import {CONFIDENCE} from './matcher.js';
|
|
18
|
+
import {launcherAvatar, launcherColour, normaliseLauncherChat as storedChat} from '../../../public/js/launcher-settings.mjs';
|
|
18
19
|
|
|
19
20
|
export const CHAT_DEFAULTS = Object.freeze({
|
|
20
21
|
confidence: 'balanced',
|
|
@@ -32,19 +33,32 @@ export const RETENTION_MAX = 730;
|
|
|
32
33
|
/** The per-launcher chat block. */
|
|
33
34
|
export const LAUNCHER_CHAT_DEFAULTS = Object.freeze({
|
|
34
35
|
greeting: 'Hi! Ask me anything about us - or ask to talk to a person.',
|
|
35
|
-
botName: '
|
|
36
|
+
botName: 'Della',
|
|
36
37
|
bot: true,
|
|
37
38
|
staff: true,
|
|
38
|
-
askDetails: 'offline'
|
|
39
|
+
askDetails: 'offline',
|
|
40
|
+
ai: true,
|
|
41
|
+
aiUseSite: true,
|
|
42
|
+
aiContext: '',
|
|
43
|
+
aiRules: '',
|
|
44
|
+
accent: '',
|
|
45
|
+
accentText: '',
|
|
46
|
+
avatar: '',
|
|
47
|
+
aiMaxPerChat: 20
|
|
39
48
|
});
|
|
40
49
|
export const ASK_DETAILS = ['offline', 'always', 'never'];
|
|
41
50
|
export const GREETING_MAX = 300;
|
|
42
51
|
export const BOT_NAME_MAX = 40;
|
|
52
|
+
export const AI_CONTEXT_MAX = 4000;
|
|
53
|
+
export const AI_RULES_MAX = 2000;
|
|
43
54
|
|
|
44
55
|
const clip = (v, max, fallback) => {
|
|
45
56
|
const s = typeof v === 'string' ? v.trim().replace(/\s+/g, ' ').slice(0, max) : '';
|
|
46
57
|
return s || fallback;
|
|
47
58
|
};
|
|
59
|
+
const block = (v, max) => (typeof v === 'string'
|
|
60
|
+
// eslint-disable-next-line no-control-regex
|
|
61
|
+
? v.replace(/\r\n?/g, '\n').replace(/[\u0000-\u0009\u000b-\u001f\u007f]/g, ' ').replace(/\n{3,}/g, '\n\n').trim().slice(0, max) : '');
|
|
48
62
|
const flag = (v, fallback) => (v === undefined || v === null ? fallback : !(v === false || v === 'false' || v === 0 || v === '0' || v === 'off'));
|
|
49
63
|
|
|
50
64
|
/**
|
|
@@ -65,7 +79,7 @@ export function normaliseChatSettings(raw) {
|
|
|
65
79
|
|
|
66
80
|
/**
|
|
67
81
|
* @param {object} [raw] - a launcher's `chat` block
|
|
68
|
-
* @returns {{greeting: string, botName: string, bot: boolean, staff: boolean, askDetails: string}}
|
|
82
|
+
* @returns {{greeting: string, botName: string, bot: boolean, staff: boolean, askDetails: string, ai: boolean, aiContext: string, aiRules: string}}
|
|
69
83
|
*/
|
|
70
84
|
export function normaliseLauncherChat(raw) {
|
|
71
85
|
const r = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
|
|
@@ -74,7 +88,19 @@ export function normaliseLauncherChat(raw) {
|
|
|
74
88
|
botName: clip(r.botName, BOT_NAME_MAX, LAUNCHER_CHAT_DEFAULTS.botName),
|
|
75
89
|
bot: flag(r.bot, true),
|
|
76
90
|
staff: flag(r.staff, true),
|
|
77
|
-
askDetails: ASK_DETAILS.includes(r.askDetails) ? r.askDetails : LAUNCHER_CHAT_DEFAULTS.askDetails
|
|
91
|
+
askDetails: ASK_DETAILS.includes(r.askDetails) ? r.askDetails : LAUNCHER_CHAT_DEFAULTS.askDetails,
|
|
92
|
+
ai: flag(r.ai, true),
|
|
93
|
+
aiUseSite: flag(r.aiUseSite, true),
|
|
94
|
+
aiContext: block(r.aiContext, AI_CONTEXT_MAX),
|
|
95
|
+
aiRules: block(r.aiRules, AI_RULES_MAX),
|
|
96
|
+
accent: launcherColour(r.accent),
|
|
97
|
+
accentText: launcherColour(r.accentText),
|
|
98
|
+
avatar: launcherAvatar(r.avatar),
|
|
99
|
+
aiMaxPerChat: Number.isFinite(Number(r.aiMaxPerChat)) && String(r.aiMaxPerChat ?? '').trim() !== ''
|
|
100
|
+
? Math.min(100, Math.max(0, Math.round(Number(r.aiMaxPerChat)))) : LAUNCHER_CHAT_DEFAULTS.aiMaxPerChat,
|
|
101
|
+
starters: storedChat(r).starters,
|
|
102
|
+
personButton: storedChat(r).personButton,
|
|
103
|
+
times: storedChat(r).times
|
|
78
104
|
};
|
|
79
105
|
}
|
|
80
106
|
|
|
@@ -441,7 +441,7 @@ export async function addMessage(id, msg, patch = {}) {
|
|
|
441
441
|
const message = await createEntry(SLUGS.messages, {
|
|
442
442
|
sessionId: id, n, from: msg.from, text: cleanText(msg.text, msg.answerId ? ANSWER_SNAPSHOT : TEXT_MAX),
|
|
443
443
|
answerId: msg.answerId || '', suggestions: Array.isArray(msg.suggestions) ? msg.suggestions : [],
|
|
444
|
-
staffName: msg.staffName || ''
|
|
444
|
+
staffName: msg.staffName || '', ...(msg.ai && {ai: true})
|
|
445
445
|
}, {source: 'chat'});
|
|
446
446
|
const at = message.meta.createdAt;
|
|
447
447
|
const data = {...session.data, ...patch, count: n, lastAt: at};
|
|
@@ -54,7 +54,8 @@ const CORE_TOOL_COLLECTIONS = Object.freeze({
|
|
|
54
54
|
'chat-knowledge': ['chats', 'manage', 'Chats'],
|
|
55
55
|
'chat-sessions': ['chats', 'manage', 'Chats'],
|
|
56
56
|
'chat-messages': ['chats', 'manage', 'Chats'],
|
|
57
|
-
'chat-unanswered': ['chats', 'manage', 'Chats']
|
|
57
|
+
'chat-unanswered': ['chats', 'manage', 'Chats'],
|
|
58
|
+
'chat-saved': ['chats', 'manage', 'Chats']
|
|
58
59
|
});
|
|
59
60
|
|
|
60
61
|
/** A row anyone with the Tool may read, whoever made it (ownership gates writes only). */
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
export const LAUNCHERS_CACHE_TAG = 'site';
|
|
26
26
|
|
|
27
27
|
/** Bumped by hand when launchers.mjs or launchers.css changes - the updater replaces public/ wholesale. */
|
|
28
|
-
export const LAUNCHERS_ASSET_V = '
|
|
28
|
+
export const LAUNCHERS_ASSET_V = '20261110-chat-times';
|
|
29
29
|
|
|
30
30
|
/** @returns {object[]} the stored launchers, normalised, in order; none when the file is missing or broken */
|
|
31
31
|
export function getLaunchers() {
|
|
@@ -500,6 +500,7 @@ const PRESETS = [
|
|
|
500
500
|
{name: 'count', label: 'Messages', type: 'number', default: 0},
|
|
501
501
|
{name: 'unread', label: 'Unread by staff', type: 'number', default: 0},
|
|
502
502
|
{name: 'misses', label: 'Unanswered in a row', type: 'number', default: 0},
|
|
503
|
+
{name: 'aiCount', label: 'AI answers', type: 'number', default: 0},
|
|
503
504
|
{name: 'askDetails', label: 'Details asked for', type: 'boolean', default: false},
|
|
504
505
|
{name: 'assignedTo', label: 'Answered by (id)', type: 'text'},
|
|
505
506
|
{name: 'assignedName', label: 'Answered by', type: 'text'},
|
|
@@ -514,7 +515,8 @@ const PRESETS = [
|
|
|
514
515
|
{name: 'text', label: 'Text', type: 'textarea'},
|
|
515
516
|
{name: 'answerId', label: 'Knowledge entry', type: 'text'},
|
|
516
517
|
{name: 'suggestions', label: 'Suggestions', type: 'json'},
|
|
517
|
-
{name: 'staffName', label: 'Staff name', type: 'text'}
|
|
518
|
+
{name: 'staffName', label: 'Staff name', type: 'text'},
|
|
519
|
+
{name: 'ai', label: 'Answered by AI', type: 'boolean', default: false}
|
|
518
520
|
]),
|
|
519
521
|
...chatPreset('chat-unanswered', 'Chat Unanswered', 'Questions the chat bot could not answer, for turning into Knowledge.', [
|
|
520
522
|
{name: 'text', label: 'Question', type: 'text', required: true},
|
|
@@ -524,6 +526,26 @@ const PRESETS = [
|
|
|
524
526
|
{name: 'firstAt', label: 'First asked', type: 'datetime'},
|
|
525
527
|
{name: 'lastAt', label: 'Last asked', type: 'datetime'},
|
|
526
528
|
{name: 'done', label: 'Dealt with', type: 'boolean', default: false}
|
|
529
|
+
]),
|
|
530
|
+
// A copy of a chat kept for a closer look (services/chat/saved.js): outlives the chat itself.
|
|
531
|
+
...chatPreset('chat-saved', 'Saved Chats', 'Chats kept for a closer look: a copy of the conversation, why it was saved, and what came of it.', [
|
|
532
|
+
{name: 'title', label: 'Title', type: 'text', required: true},
|
|
533
|
+
{name: 'note', label: 'Why it was saved', type: 'textarea'},
|
|
534
|
+
{name: 'outcome', label: 'Outcome', type: 'select', options: ['to look at', 'looking into it', 'done'], default: 'to look at'},
|
|
535
|
+
{name: 'visitorName', label: 'Name', type: 'text'},
|
|
536
|
+
{name: 'visitorEmail', label: 'Email', type: 'text'},
|
|
537
|
+
{name: 'page', label: 'Page', type: 'text'},
|
|
538
|
+
{name: 'startedAt', label: 'Chat started', type: 'datetime'},
|
|
539
|
+
{name: 'lastAt', label: 'Last message', type: 'datetime'},
|
|
540
|
+
{name: 'savedAt', label: 'Saved', type: 'datetime'},
|
|
541
|
+
{name: 'savedByName', label: 'Saved by', type: 'text'},
|
|
542
|
+
{name: 'savedBy', label: 'Saved by (id)', type: 'hidden'},
|
|
543
|
+
{name: 'chatId', label: 'Chat', type: 'hidden'},
|
|
544
|
+
{name: 'launcherId', label: 'Launcher', type: 'text'},
|
|
545
|
+
{name: 'chatStatus', label: 'Chat status when saved', type: 'text'},
|
|
546
|
+
{name: 'messageCount', label: 'Messages', type: 'number', default: 0},
|
|
547
|
+
{name: 'transcript', label: 'Conversation', type: 'textarea'},
|
|
548
|
+
{name: 'messages', label: 'Messages (data)', type: 'json'}
|
|
527
549
|
])
|
|
528
550
|
];
|
|
529
551
|
|
|
@@ -541,7 +563,7 @@ export const PRESET_COLLECTION_SLUGS = PRESETS.map(p => p.slug);
|
|
|
541
563
|
export const USER_DATA_PRESET_SLUGS = Object.freeze(['notes-notes', 'todo-items', 'contacts-contacts', 'contacts-groups']);
|
|
542
564
|
|
|
543
565
|
/** The chat presets (services/chat/store.js). */
|
|
544
|
-
export const CHAT_PRESET_SLUGS = Object.freeze(['chat-knowledge', 'chat-sessions', 'chat-messages', 'chat-unanswered']);
|
|
566
|
+
export const CHAT_PRESET_SLUGS = Object.freeze(['chat-knowledge', 'chat-sessions', 'chat-messages', 'chat-unanswered', 'chat-saved']);
|
|
545
567
|
|
|
546
568
|
/**
|
|
547
569
|
* The presets that may live in MongoDB (adapterRegistry.js resolveUserDataPreset):
|
|
@@ -91,7 +91,7 @@ export const PRIVATE_DATA = [
|
|
|
91
91
|
'jb-applications', 'jb-candidate-profiles', 'jb-signups',
|
|
92
92
|
// Visitor chat (Launchers, 1.28.0): conversations, names and emails, and the
|
|
93
93
|
// questions visitors asked. The Knowledge (chat-knowledge) is authored and stays.
|
|
94
|
-
'chat-sessions', 'chat-messages', 'chat-unanswered',
|
|
94
|
+
'chat-sessions', 'chat-messages', 'chat-unanswered', 'chat-saved',
|
|
95
95
|
// Games: each play carries the player's name and their resume token.
|
|
96
96
|
'quiz-plays', 'crossword-plays', 'daily-word-plays', 'word-search-plays',
|
|
97
97
|
// Outreach (Surveys, Campaigns): recipients, sends, claims, opens and clicks,
|