@botfabrik/engine-webclient 4.101.2 → 4.101.3-alpha.1
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/dist/auth/auth-pages.js +3 -8
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +35 -39
- package/dist/auth/relay-state.js +6 -17
- package/dist/auth/ttl-cache.js +1 -5
- package/dist/constants.js +1 -4
- package/dist/createSessionInfo.d.ts +2 -2
- package/dist/createSessionInfo.js +3 -5
- package/dist/createSessionInfo.test.d.ts +1 -0
- package/dist/createSessionInfo.test.js +40 -45
- package/dist/extractLocale.js +3 -5
- package/dist/extractLocale.test.d.ts +1 -0
- package/dist/extractLocale.test.js +13 -18
- package/dist/getSupportedClientLocale.js +1 -3
- package/dist/getSupportedClientLocale.test.d.ts +1 -0
- package/dist/getSupportedClientLocale.test.js +15 -20
- package/dist/index.d.ts +2 -2
- package/dist/index.js +45 -64
- package/dist/loadPreviousConversation.js +5 -7
- package/dist/middleware/index.d.ts +1 -1
- package/dist/middleware/index.js +20 -25
- package/dist/requestSessionData.d.ts +1 -1
- package/dist/requestSessionData.js +5 -7
- package/dist/requestSessionData.test.d.ts +1 -0
- package/dist/requestSessionData.test.js +42 -52
- package/dist/setTranslations.js +4 -6
- package/dist/speechToText.d.ts +1 -1
- package/dist/speechToText.js +3 -5
- package/dist/types.js +2 -5
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/dist/views/index.js +1 -3
- package/package.json +21 -10
package/dist/index.js
CHANGED
|
@@ -1,47 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const engine_domain_1 = require("@botfabrik/engine-domain");
|
|
21
|
-
const engine_transcript_export_1 = require("@botfabrik/engine-transcript-export");
|
|
22
|
-
const express_1 = require("express");
|
|
23
|
-
const package_json_1 = require("../package.json");
|
|
24
|
-
const auth_1 = require("./auth");
|
|
25
|
-
const constants_1 = require("./constants");
|
|
26
|
-
const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
27
|
-
const extractLocale_1 = __importDefault(require("./extractLocale"));
|
|
28
|
-
const getSupportedClientLocale_1 = __importDefault(require("./getSupportedClientLocale"));
|
|
29
|
-
const loadPreviousConversation_1 = __importDefault(require("./loadPreviousConversation"));
|
|
30
|
-
const middleware_1 = __importDefault(require("./middleware"));
|
|
31
|
-
const requestSessionData_1 = __importDefault(require("./requestSessionData"));
|
|
32
|
-
const setTranslations_1 = __importDefault(require("./setTranslations"));
|
|
33
|
-
const speechToText_1 = __importDefault(require("./speechToText"));
|
|
34
|
-
const types_1 = require("./types");
|
|
35
|
-
const views_1 = __importDefault(require("./views"));
|
|
36
|
-
__exportStar(require("./types"), exports);
|
|
37
|
-
exports.default = (clientName, environment, props) => async (bot) => {
|
|
38
|
-
const logger = bot.logger.child({ clientType: constants_1.CLIENT_TYPE, clientName });
|
|
1
|
+
import { Actions, ActionTypes, BotUser, TextMessage, } from '@botfabrik/engine-domain';
|
|
2
|
+
import { getPdf } from '@botfabrik/engine-transcript-export';
|
|
3
|
+
import { static as serveStatic } from 'express';
|
|
4
|
+
import { setUpSamlAuth, storeLoginRequestToken, verifyLoginToken, } from './auth/index.js';
|
|
5
|
+
import { CLIENT_TYPE } from './constants.js';
|
|
6
|
+
import createSessionInfo from './createSessionInfo.js';
|
|
7
|
+
import extractLocale from './extractLocale.js';
|
|
8
|
+
import getSupportedClientLocale from './getSupportedClientLocale.js';
|
|
9
|
+
import loadPreviousConversation from './loadPreviousConversation.js';
|
|
10
|
+
import middleware from './middleware/index.js';
|
|
11
|
+
import requestSessionData from './requestSessionData.js';
|
|
12
|
+
import setTranslations from './setTranslations.js';
|
|
13
|
+
import speechToText from './speechToText.js';
|
|
14
|
+
import { Devices, } from './types.js';
|
|
15
|
+
import { version } from './version.js';
|
|
16
|
+
import index from './views/index.js';
|
|
17
|
+
export * from './types.js';
|
|
18
|
+
export default (clientName, environment, props) => async (bot) => {
|
|
19
|
+
const logger = bot.logger.child({ clientType: CLIENT_TYPE, clientName });
|
|
39
20
|
// serve transcript pdf
|
|
40
21
|
bot.webserver.express.use('/transcript-pdf/:sessionId', async (req, res) => {
|
|
41
22
|
const sessionId = req.params['sessionId'];
|
|
42
23
|
if (sessionId?.length) {
|
|
43
24
|
const session = await bot.createSession(sessionId);
|
|
44
|
-
const pdf = await
|
|
25
|
+
const pdf = await getPdf(session);
|
|
45
26
|
res.set('Content-Type', 'application/pdf');
|
|
46
27
|
res.set('Content-Disposition', 'attachment; filename="Transcript.pdf"');
|
|
47
28
|
res.end(pdf);
|
|
@@ -64,7 +45,7 @@ exports.default = (clientName, environment, props) => async (bot) => {
|
|
|
64
45
|
}
|
|
65
46
|
}
|
|
66
47
|
res.set('Content-Type', 'text/html; charset=utf-8');
|
|
67
|
-
res.write((
|
|
48
|
+
res.write(index(serverUrl.toString(), `${server}/embed/bundle.js`));
|
|
68
49
|
res.end();
|
|
69
50
|
});
|
|
70
51
|
if (!isFabVisible(props)) {
|
|
@@ -80,7 +61,7 @@ exports.default = (clientName, environment, props) => async (bot) => {
|
|
|
80
61
|
}
|
|
81
62
|
});
|
|
82
63
|
}
|
|
83
|
-
bot.webserver.express.use(`/${clientName}/embed`, (
|
|
64
|
+
bot.webserver.express.use(`/${clientName}/embed`, serveStatic(__dirname + '/embed', serveStaticOptions));
|
|
84
65
|
bot.webserver.express.get(`/${clientName}/logo.svg`, (_req, res) => {
|
|
85
66
|
res.redirect(`/cms/chatbot/design/logo.svg?client=${clientName}`);
|
|
86
67
|
});
|
|
@@ -91,7 +72,7 @@ exports.default = (clientName, environment, props) => async (bot) => {
|
|
|
91
72
|
res.redirect(`/cms/chatbot/design/fab.svg?client=${clientName}`);
|
|
92
73
|
});
|
|
93
74
|
// serve chat client resources
|
|
94
|
-
bot.webserver.express.use(`/${clientName}`, (
|
|
75
|
+
bot.webserver.express.use(`/${clientName}`, serveStatic(__dirname + '/client', serveStaticOptions));
|
|
95
76
|
logger.info(`Webclient will be available on route: /${clientName}`);
|
|
96
77
|
const nsp = bot.webserver.socket.of(`/${clientName}/chat`);
|
|
97
78
|
nsp.on('connection', async (socket) => {
|
|
@@ -101,23 +82,23 @@ exports.default = (clientName, environment, props) => async (bot) => {
|
|
|
101
82
|
socket.on('terminate-session', onTerminateSession(socket, bot));
|
|
102
83
|
if (props.auth) {
|
|
103
84
|
socket.on('login-requested', (data) => {
|
|
104
|
-
|
|
85
|
+
storeLoginRequestToken(data.loginRequestToken, socket.id);
|
|
105
86
|
});
|
|
106
87
|
}
|
|
107
88
|
}
|
|
108
89
|
catch (error) {
|
|
109
90
|
logger.error('Error while connecting webclient with backend.');
|
|
110
91
|
logger.error(error);
|
|
111
|
-
const errorMessage = new
|
|
112
|
-
socket.emit('action',
|
|
92
|
+
const errorMessage = new TextMessage('Sorry I can’t talk at the moment. Please try again later.', new BotUser());
|
|
93
|
+
socket.emit('action', Actions.sendMessageToGuest(errorMessage));
|
|
113
94
|
}
|
|
114
95
|
});
|
|
115
96
|
if (props.auth) {
|
|
116
|
-
|
|
97
|
+
setUpSamlAuth(bot, props.auth, clientName, nsp);
|
|
117
98
|
}
|
|
118
99
|
const client = {
|
|
119
100
|
name: `${clientName}Webclient`,
|
|
120
|
-
middleware: (
|
|
101
|
+
middleware: middleware(clientName, nsp),
|
|
121
102
|
};
|
|
122
103
|
return client;
|
|
123
104
|
};
|
|
@@ -133,7 +114,7 @@ const serveStaticOptions = {
|
|
|
133
114
|
res.setHeader('Cache-Control', 'max-age=31536000');
|
|
134
115
|
}
|
|
135
116
|
else {
|
|
136
|
-
res.setHeader('ETag',
|
|
117
|
+
res.setHeader('ETag', version);
|
|
137
118
|
}
|
|
138
119
|
},
|
|
139
120
|
};
|
|
@@ -142,21 +123,21 @@ const onTerminateSession = (socket, bot) => async ({ sessionId, // passed if the
|
|
|
142
123
|
}) => {
|
|
143
124
|
const session = await bot.createSession(sessionId);
|
|
144
125
|
socket.leave(sessionId);
|
|
145
|
-
await session.dispatch(
|
|
126
|
+
await session.dispatch(Actions.guestDisconnected(sessionId));
|
|
146
127
|
};
|
|
147
128
|
const onStartChat = (socket, props, bot, clientName, environment, logger) => async ({ sessionId: sessionIdFromClient, userId: defaultUserId, querystrings, loginToken, }) => {
|
|
148
129
|
try {
|
|
149
|
-
const authenticatedUser =
|
|
150
|
-
const locale = (
|
|
130
|
+
const authenticatedUser = await verifyLoginToken(loginToken, props.auth, logger);
|
|
131
|
+
const locale = extractLocale(querystrings, socket.request.headers['accept-language']);
|
|
151
132
|
const sessionsCollection = bot.store.db.collection('sessions');
|
|
152
|
-
const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await (
|
|
133
|
+
const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await requestSessionData(sessionIdFromClient, querystrings, sessionsCollection, clientName, props);
|
|
153
134
|
// create a channel for each session
|
|
154
135
|
socket.join(sessionId);
|
|
155
|
-
const sessionInfo = await (
|
|
136
|
+
const sessionInfo = await createSessionInfo(socket, clientName, environment, defaultSessionInfo, defaultUserId, locale, querystrings, authenticatedUser, props)();
|
|
156
137
|
const session = await bot.createSession(sessionId, sessionInfo);
|
|
157
138
|
sendConfigurationToClient(socket, props, bot, clientName);
|
|
158
139
|
// sending persisted state to client
|
|
159
|
-
const previousConversations = await (
|
|
140
|
+
const previousConversations = await loadPreviousConversation(bot.store, sessionId);
|
|
160
141
|
socket.emit('restore-client-state', {
|
|
161
142
|
sessionId,
|
|
162
143
|
messages: previousConversations,
|
|
@@ -168,7 +149,7 @@ const onStartChat = (socket, props, bot, clientName, environment, logger) => asy
|
|
|
168
149
|
});
|
|
169
150
|
}
|
|
170
151
|
// Notify middlewares about a connected or reconnected guest
|
|
171
|
-
await session.dispatch(
|
|
152
|
+
await session.dispatch(Actions.guestConnected(sessionId));
|
|
172
153
|
if (isNew && props.getStartedAction) {
|
|
173
154
|
await session.dispatch(props.getStartedAction);
|
|
174
155
|
}
|
|
@@ -176,24 +157,24 @@ const onStartChat = (socket, props, bot, clientName, environment, logger) => asy
|
|
|
176
157
|
await session.dispatch(JSON.parse(action));
|
|
177
158
|
});
|
|
178
159
|
registerListener(socket, 'disconnect', async () => {
|
|
179
|
-
await session.dispatch(
|
|
160
|
+
await session.dispatch(Actions.guestDisconnected(sessionId));
|
|
180
161
|
});
|
|
181
162
|
registerListener(socket, 'conversation-rating', async (rating) => {
|
|
182
163
|
sessionsCollection.updateOne({ _id: sessionId }, {
|
|
183
164
|
$set: { 'sessionInfo.client.payload.conversationRating': rating },
|
|
184
165
|
});
|
|
185
166
|
session.dispatch({
|
|
186
|
-
type:
|
|
167
|
+
type: ActionTypes.CONVERSATION_RATING_FROM_GUEST,
|
|
187
168
|
payload: { rating },
|
|
188
169
|
});
|
|
189
170
|
});
|
|
190
171
|
registerListener(socket, 'audio-message', async (buffer) => {
|
|
191
172
|
if (props.speech) {
|
|
192
173
|
try {
|
|
193
|
-
const text = await (
|
|
174
|
+
const text = await speechToText(props.speech, session.translator.locale, buffer);
|
|
194
175
|
if (text && text.length) {
|
|
195
176
|
socket.emit('speech-transcription', text);
|
|
196
|
-
session.dispatch(
|
|
177
|
+
session.dispatch(Actions.receiveTextMessageFromGuest(text));
|
|
197
178
|
}
|
|
198
179
|
}
|
|
199
180
|
catch (error) {
|
|
@@ -215,12 +196,12 @@ const registerListener = (socket, event, listener) => {
|
|
|
215
196
|
};
|
|
216
197
|
const sendConfigurationToClient = (socket, props, bot, clientName) => {
|
|
217
198
|
// sending active language and translations to client
|
|
218
|
-
const locale = (
|
|
199
|
+
const locale = extractLocale(socket.handshake.query, socket.request.headers['accept-language']);
|
|
219
200
|
const supportedLocale = bot.translation.detectSupportedLocale(locale);
|
|
220
|
-
const clientLocale = (
|
|
221
|
-
(
|
|
201
|
+
const clientLocale = getSupportedClientLocale(supportedLocale);
|
|
202
|
+
setTranslations(socket, bot, clientLocale, clientName);
|
|
222
203
|
const settings = {
|
|
223
|
-
version
|
|
204
|
+
version,
|
|
224
205
|
requiresUserAuthentication: !!props.auth,
|
|
225
206
|
enableStartScreen: !!props.enableStartScreen || !!props.auth,
|
|
226
207
|
enableStandaloneView: !!props.enableStandaloneView,
|
|
@@ -233,7 +214,7 @@ const sendConfigurationToClient = (socket, props, bot, clientName) => {
|
|
|
233
214
|
};
|
|
234
215
|
socket.emit('set-settings', settings);
|
|
235
216
|
if (props.expandChatWindowAtStart &&
|
|
236
|
-
props.expandChatWindowAtStart !==
|
|
217
|
+
props.expandChatWindowAtStart !== Devices.None) {
|
|
237
218
|
socket.emit('expand-window', {
|
|
238
219
|
devices: props.expandChatWindowAtStart,
|
|
239
220
|
initial: true,
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const engine_domain_1 = require("@botfabrik/engine-domain");
|
|
1
|
+
import { ActionTypes, } from '@botfabrik/engine-domain';
|
|
4
2
|
const loadPreviousConversations = async (store, sessionId) => {
|
|
5
3
|
const actionLogs = await store.db
|
|
6
4
|
.collection('actionlog')
|
|
@@ -9,9 +7,9 @@ const loadPreviousConversations = async (store, sessionId) => {
|
|
|
9
7
|
{ _sessionId: sessionId },
|
|
10
8
|
{
|
|
11
9
|
$or: [
|
|
12
|
-
{ type:
|
|
13
|
-
{ type:
|
|
14
|
-
{ type:
|
|
10
|
+
{ type: ActionTypes.MESSAGE_FROM_GUEST },
|
|
11
|
+
{ type: ActionTypes.MESSAGE_WITHOUT_ANALYSIS_FROM_GUEST },
|
|
12
|
+
{ type: ActionTypes.MESSAGE_TO_GUEST },
|
|
15
13
|
],
|
|
16
14
|
},
|
|
17
15
|
],
|
|
@@ -34,4 +32,4 @@ const loadPreviousConversations = async (store, sessionId) => {
|
|
|
34
32
|
});
|
|
35
33
|
return messages;
|
|
36
34
|
};
|
|
37
|
-
|
|
35
|
+
export default loadPreviousConversations;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Middleware } from '@botfabrik/engine-domain';
|
|
2
2
|
import type { Namespace } from 'socket.io';
|
|
3
|
-
import { type WebclientMiddlewareState } from '../types';
|
|
3
|
+
import { type WebclientMiddlewareState } from '../types.js';
|
|
4
4
|
declare const _default: (clientName: string, nsp: Namespace) => Middleware<WebclientMiddlewareState>;
|
|
5
5
|
export default _default;
|
package/dist/middleware/index.js
CHANGED
|
@@ -1,40 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
const engine_domain_1 = require("@botfabrik/engine-domain");
|
|
7
|
-
const engine_utils_1 = require("@botfabrik/engine-utils");
|
|
8
|
-
const setTranslations_1 = __importDefault(require("../setTranslations"));
|
|
9
|
-
const types_1 = require("../types");
|
|
10
|
-
exports.default = (clientName, nsp) => async (bot) => {
|
|
1
|
+
import { ActionTypes, } from '@botfabrik/engine-domain';
|
|
2
|
+
import { waitFor, waitForTyping } from '@botfabrik/engine-utils';
|
|
3
|
+
import setTranslations from '../setTranslations.js';
|
|
4
|
+
import { Devices, } from '../types.js';
|
|
5
|
+
export default (clientName, nsp) => async (bot) => {
|
|
11
6
|
return async (next, _state, action, session) => {
|
|
12
7
|
const sessionInfo = session.getSessionInfo();
|
|
13
8
|
const clientInfo = sessionInfo.client;
|
|
14
9
|
if (clientInfo.type === 'webclient' && clientInfo.name === clientName) {
|
|
15
10
|
switch (action.type) {
|
|
16
|
-
case
|
|
11
|
+
case ActionTypes.MESSAGE_TO_GUEST:
|
|
17
12
|
await emitMessageToGuestAction(nsp, session, action);
|
|
18
13
|
break;
|
|
19
|
-
case
|
|
20
|
-
case
|
|
21
|
-
case
|
|
22
|
-
case
|
|
23
|
-
case
|
|
24
|
-
case
|
|
25
|
-
case
|
|
14
|
+
case ActionTypes.TYPING_ON:
|
|
15
|
+
case ActionTypes.TYPING_OFF:
|
|
16
|
+
case ActionTypes.EVENT_TO_GUEST:
|
|
17
|
+
case ActionTypes.MESSAGE_FROM_GUEST:
|
|
18
|
+
case ActionTypes.MESSAGE_WITHOUT_ANALYSIS_FROM_GUEST:
|
|
19
|
+
case ActionTypes.DRAWER_OPEN:
|
|
20
|
+
case ActionTypes.DRAWER_CLOSE:
|
|
26
21
|
await sendToChatClient(nsp, session, action);
|
|
27
22
|
break;
|
|
28
23
|
case 'webclient.window.expand':
|
|
29
24
|
expandChatWindow(nsp, session, action);
|
|
30
25
|
break;
|
|
31
|
-
case
|
|
26
|
+
case ActionTypes.RESTART_CHAT_REQUEST:
|
|
32
27
|
restartChat(nsp, session);
|
|
33
28
|
break;
|
|
34
|
-
case
|
|
29
|
+
case ActionTypes.GUEST_LOCALE_CHANGED:
|
|
35
30
|
{
|
|
36
31
|
const { locale } = session.translator;
|
|
37
|
-
(
|
|
32
|
+
setTranslations(nsp, bot, locale, clientName);
|
|
38
33
|
await sendToChatClient(nsp, session, action);
|
|
39
34
|
}
|
|
40
35
|
break;
|
|
@@ -46,18 +41,18 @@ exports.default = (clientName, nsp) => async (bot) => {
|
|
|
46
41
|
const emitMessageToGuestAction = async (nsp, session, action) => {
|
|
47
42
|
const useTyping = !action.noTypingDelay;
|
|
48
43
|
if (useTyping) {
|
|
49
|
-
nsp.to(session.id).emit('action', { type:
|
|
50
|
-
await
|
|
44
|
+
nsp.to(session.id).emit('action', { type: ActionTypes.TYPING_ON });
|
|
45
|
+
await waitForTyping(action['message']);
|
|
51
46
|
}
|
|
52
47
|
await sendToChatClient(nsp, session, action);
|
|
53
|
-
await
|
|
48
|
+
await waitFor(500);
|
|
54
49
|
};
|
|
55
50
|
const sendToChatClient = async (nsp, session, action) => {
|
|
56
51
|
nsp.to(session.id).emit('action', action);
|
|
57
52
|
};
|
|
58
53
|
const expandChatWindow = (nsp, session, action) => {
|
|
59
54
|
const devices = action.payload?.devices;
|
|
60
|
-
if (!!devices && devices !==
|
|
55
|
+
if (!!devices && devices !== Devices.None) {
|
|
61
56
|
nsp
|
|
62
57
|
.to(session.id)
|
|
63
58
|
.emit('expand-window', { devices: action.payload.devices });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SessionInfo } from '@botfabrik/engine-domain';
|
|
2
|
-
import type { SessionInfoClientPayload, SessionInfoUserPayload, WebClientProps } from './types';
|
|
2
|
+
import type { SessionInfoClientPayload, SessionInfoUserPayload, WebClientProps } from './types.js';
|
|
3
3
|
interface SessionData {
|
|
4
4
|
sessionId: string;
|
|
5
5
|
sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const crypto_1 = require("crypto");
|
|
4
|
-
const constants_1 = require("./constants");
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { CLIENT_TYPE } from './constants.js';
|
|
5
3
|
const requestSessionData = async (sessionId, querystrings, sessionsCollection, clientName, props) => {
|
|
6
4
|
const baseQuery = {
|
|
7
|
-
'sessionInfo.client.type':
|
|
5
|
+
'sessionInfo.client.type': CLIENT_TYPE,
|
|
8
6
|
'sessionInfo.client.name': clientName,
|
|
9
7
|
};
|
|
10
8
|
let findSessionRecordQuery;
|
|
@@ -31,7 +29,7 @@ const requestSessionData = async (sessionId, querystrings, sessionsCollection, c
|
|
|
31
29
|
isNew = false;
|
|
32
30
|
}
|
|
33
31
|
else {
|
|
34
|
-
sesId =
|
|
32
|
+
sesId = randomUUID();
|
|
35
33
|
sessionInfo = {
|
|
36
34
|
client: {},
|
|
37
35
|
user: {},
|
|
@@ -45,4 +43,4 @@ const requestSessionData = async (sessionId, querystrings, sessionsCollection, c
|
|
|
45
43
|
isNew,
|
|
46
44
|
};
|
|
47
45
|
};
|
|
48
|
-
|
|
46
|
+
export default requestSessionData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,107 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const original = globals_1.jest.requireActual('crypto');
|
|
10
|
-
return {
|
|
11
|
-
v4: globals_1.jest.fn(() => 'uuid'),
|
|
12
|
-
...original,
|
|
13
|
-
randomUUID: globals_1.jest.fn(() => 'some-uuid'),
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
(0, globals_1.describe)('request session id', () => {
|
|
17
|
-
(0, globals_1.beforeEach)(() => {
|
|
18
|
-
globals_1.jest.clearAllMocks();
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import requestSessionData from './requestSessionData.js';
|
|
3
|
+
vi.mock('node:crypto', () => ({
|
|
4
|
+
randomUUID: vi.fn(() => 'some-uuid'),
|
|
5
|
+
}));
|
|
6
|
+
describe('request session id', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
vi.clearAllMocks();
|
|
19
9
|
});
|
|
20
10
|
const querystrings = {
|
|
21
11
|
accessToken: 'access-token',
|
|
22
12
|
};
|
|
23
|
-
|
|
24
|
-
const findOne =
|
|
13
|
+
it('when sessionId has been passed by query param but does not exists in db', async () => {
|
|
14
|
+
const findOne = vi.fn();
|
|
25
15
|
findOne.mockReturnValueOnce(undefined);
|
|
26
16
|
const sessionsCollection = {
|
|
27
17
|
findOne,
|
|
28
18
|
};
|
|
29
|
-
const { sessionId, isNew } = await (
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
const { sessionId, isNew } = await requestSessionData('session-id', querystrings, sessionsCollection, 'test-bot', {});
|
|
20
|
+
expect(findOne).toHaveBeenCalledTimes(1);
|
|
21
|
+
expect(findOne).toHaveBeenCalledWith({
|
|
32
22
|
_id: 'session-id',
|
|
33
23
|
'sessionInfo.client.name': 'test-bot',
|
|
34
24
|
'sessionInfo.client.type': 'webclient',
|
|
35
25
|
}, { _id: 1, sessionInfo: 1 });
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
expect(sessionId).toBe('some-uuid');
|
|
27
|
+
expect(isNew).toBe(true);
|
|
38
28
|
});
|
|
39
|
-
|
|
40
|
-
const findOne =
|
|
29
|
+
it('when sessionId has been passed by query param and exists in db', async () => {
|
|
30
|
+
const findOne = vi.fn();
|
|
41
31
|
findOne.mockReturnValueOnce({ _id: 'session-id' });
|
|
42
32
|
const sessionsCollection = {
|
|
43
33
|
findOne,
|
|
44
34
|
};
|
|
45
|
-
const { sessionId, isNew } = await (
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
const { sessionId, isNew } = await requestSessionData('session-id', querystrings, sessionsCollection, 'test-bot', {});
|
|
36
|
+
expect(findOne).toHaveBeenCalledTimes(1);
|
|
37
|
+
expect(findOne).toHaveBeenCalledWith({
|
|
48
38
|
_id: 'session-id',
|
|
49
39
|
'sessionInfo.client.name': 'test-bot',
|
|
50
40
|
'sessionInfo.client.type': 'webclient',
|
|
51
41
|
}, { _id: 1, sessionInfo: 1 });
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
expect(sessionId).toBe('session-id');
|
|
43
|
+
expect(isNew).toBe(false);
|
|
54
44
|
});
|
|
55
|
-
|
|
56
|
-
const findOne =
|
|
45
|
+
it('when requestSessionRecordQuery has been passed as webclient property but no such session exists in db', async () => {
|
|
46
|
+
const findOne = vi.fn();
|
|
57
47
|
findOne.mockReturnValueOnce(undefined);
|
|
58
48
|
const sessionsCollection = {
|
|
59
49
|
findOne,
|
|
60
50
|
};
|
|
61
|
-
const requestSessionRecordQuery =
|
|
51
|
+
const requestSessionRecordQuery = vi.fn();
|
|
62
52
|
const props = {
|
|
63
53
|
requestSessionRecordQuery,
|
|
64
54
|
};
|
|
65
55
|
requestSessionRecordQuery.mockReturnValueOnce(Promise.resolve({ 'sessionInfo.user.id': 'hans@apptiva.ch' }));
|
|
66
|
-
const { sessionId, isNew } = await (
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
const { sessionId, isNew } = await requestSessionData('session-id', querystrings, sessionsCollection, 'test-bot', props);
|
|
57
|
+
expect(requestSessionRecordQuery).toHaveBeenCalledTimes(1);
|
|
58
|
+
expect(requestSessionRecordQuery).toHaveBeenCalledWith({
|
|
69
59
|
querystrings,
|
|
70
60
|
sessionId: 'session-id',
|
|
71
61
|
});
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
expect(findOne).toHaveBeenCalledTimes(1);
|
|
63
|
+
expect(findOne).toHaveBeenCalledWith({
|
|
74
64
|
'sessionInfo.client.name': 'test-bot',
|
|
75
65
|
'sessionInfo.client.type': 'webclient',
|
|
76
66
|
'sessionInfo.user.id': 'hans@apptiva.ch',
|
|
77
67
|
}, { _id: 1, sessionInfo: 1 });
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
expect(sessionId).toBe('some-uuid');
|
|
69
|
+
expect(isNew).toBe(true);
|
|
80
70
|
});
|
|
81
|
-
|
|
82
|
-
const findOne =
|
|
71
|
+
it('when requestSessionRecordQuery has been passed as webclient property and session exists in db', async () => {
|
|
72
|
+
const findOne = vi.fn();
|
|
83
73
|
findOne.mockReturnValueOnce({ _id: 'session-id' });
|
|
84
74
|
const sessionsCollection = {
|
|
85
75
|
findOne,
|
|
86
76
|
};
|
|
87
|
-
const requestSessionRecordQuery =
|
|
77
|
+
const requestSessionRecordQuery = vi.fn();
|
|
88
78
|
const props = {
|
|
89
79
|
requestSessionRecordQuery,
|
|
90
80
|
};
|
|
91
81
|
requestSessionRecordQuery.mockReturnValueOnce(Promise.resolve({ 'sessionInfo.user.id': 'hans@apptiva.ch' }));
|
|
92
|
-
const { sessionId, isNew } = await (
|
|
93
|
-
|
|
94
|
-
|
|
82
|
+
const { sessionId, isNew } = await requestSessionData('session-id', querystrings, sessionsCollection, 'test-bot', props);
|
|
83
|
+
expect(requestSessionRecordQuery).toHaveBeenCalledTimes(1);
|
|
84
|
+
expect(requestSessionRecordQuery).toHaveBeenCalledWith({
|
|
95
85
|
querystrings,
|
|
96
86
|
sessionId: 'session-id',
|
|
97
87
|
});
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
expect(findOne).toHaveBeenCalledTimes(1);
|
|
89
|
+
expect(findOne).toHaveBeenCalledWith({
|
|
100
90
|
'sessionInfo.client.name': 'test-bot',
|
|
101
91
|
'sessionInfo.client.type': 'webclient',
|
|
102
92
|
'sessionInfo.user.id': 'hans@apptiva.ch',
|
|
103
93
|
}, { _id: 1, sessionInfo: 1 });
|
|
104
|
-
|
|
105
|
-
|
|
94
|
+
expect(sessionId).toBe('session-id');
|
|
95
|
+
expect(isNew).toBe(false);
|
|
106
96
|
});
|
|
107
97
|
});
|
package/dist/setTranslations.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const flat_1 = require("flat");
|
|
1
|
+
import { flatten } from 'flat';
|
|
4
2
|
const TRANSLATION_KEY = 'website-messenger';
|
|
5
3
|
const setTranslations = (socket, bot, clientLocale, clientName) => {
|
|
6
4
|
socket.emit('set-translations', clientLocale, getTranslationsByClient(bot, clientLocale, clientName));
|
|
@@ -9,9 +7,9 @@ const getTranslationsByClient = (bot, clientLocale, clientName) => {
|
|
|
9
7
|
const webMessengerTranslations = bot.translation.getResourceBundle(clientLocale)[TRANSLATION_KEY] || {};
|
|
10
8
|
const defaults = webMessengerTranslations['defaults'] || {};
|
|
11
9
|
const overrides = webMessengerTranslations['overrides']?.[clientName] || {};
|
|
12
|
-
const defaultFlat =
|
|
13
|
-
const overrideFlat =
|
|
10
|
+
const defaultFlat = flatten(defaults);
|
|
11
|
+
const overrideFlat = flatten(overrides);
|
|
14
12
|
const mergedTranslations = { ...defaultFlat, ...overrideFlat };
|
|
15
13
|
return mergedTranslations;
|
|
16
14
|
};
|
|
17
|
-
|
|
15
|
+
export default setTranslations;
|
package/dist/speechToText.d.ts
CHANGED
package/dist/speechToText.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const speech_1 = require("@google-cloud/speech");
|
|
1
|
+
import { SpeechClient } from '@google-cloud/speech';
|
|
4
2
|
const speechToText = (speechProps, locale, speechBytes) => {
|
|
5
3
|
return new Promise((resolve, reject) => {
|
|
6
4
|
const speechConfig = {
|
|
@@ -9,7 +7,7 @@ const speechToText = (speechProps, locale, speechBytes) => {
|
|
|
9
7
|
client_email: speechProps.clientEmail,
|
|
10
8
|
},
|
|
11
9
|
};
|
|
12
|
-
const client = new
|
|
10
|
+
const client = new SpeechClient(speechConfig);
|
|
13
11
|
// The audio file's encoding, sample rate in hertz, and BCP-47 language code
|
|
14
12
|
const audio = {
|
|
15
13
|
content: speechBytes,
|
|
@@ -45,4 +43,4 @@ const speechToText = (speechProps, locale, speechBytes) => {
|
|
|
45
43
|
.catch(reject);
|
|
46
44
|
});
|
|
47
45
|
};
|
|
48
|
-
|
|
46
|
+
export default speechToText;
|
package/dist/types.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Devices = void 0;
|
|
4
|
-
var Devices;
|
|
1
|
+
export var Devices;
|
|
5
2
|
(function (Devices) {
|
|
6
3
|
Devices["All"] = "all";
|
|
7
4
|
Devices["Mobile"] = "mobile";
|
|
8
5
|
Devices["Desktop"] = "desktop";
|
|
9
6
|
Devices["None"] = "none";
|
|
10
|
-
})(Devices || (
|
|
7
|
+
})(Devices || (Devices = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version: string;
|
package/dist/version.js
ADDED
package/dist/views/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
const index = (server, scriptUrl) => `<!DOCTYPE html>
|
|
4
2
|
<html lang="de">
|
|
5
3
|
<head>
|
|
@@ -166,4 +164,4 @@ const index = (server, scriptUrl) => `<!DOCTYPE html>
|
|
|
166
164
|
</body>
|
|
167
165
|
</html>
|
|
168
166
|
`;
|
|
169
|
-
|
|
167
|
+
export default index;
|