@botfabrik/engine-webclient 4.36.1 → 4.37.3
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.
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import type { SessionInfo
|
|
2
|
-
import type
|
|
1
|
+
import type { SessionInfo } from '@botfabrik/engine-core';
|
|
2
|
+
import type { Environment } from '@botfabrik/engine-domain';
|
|
3
3
|
import type { Socket } from 'socket.io';
|
|
4
4
|
import { WebClientProps } from './index';
|
|
5
5
|
import type { SessionInfoClientPayload, SessionInfoUserPayload } from './types';
|
|
6
|
-
|
|
7
|
-
client: SessionInfoClient<SessionInfoClientPayload>;
|
|
8
|
-
user: SessionInfoUser<SessionInfoUserPayload>;
|
|
9
|
-
contexts: string[];
|
|
10
|
-
}>;
|
|
11
|
-
declare const createSessionInfo: (socket: Socket, name: string, sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>, props: WebClientProps) => () => Promise<SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>>;
|
|
6
|
+
declare const createSessionInfo: (socket: Socket, clientName: string, environment: Environment, sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>, props: WebClientProps) => () => Promise<SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>>;
|
|
12
7
|
export default createSessionInfo;
|
|
@@ -3,22 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createSessionInfoFromRequest = void 0;
|
|
7
6
|
const buildUserAgentInfos_1 = __importDefault(require("./buildUserAgentInfos"));
|
|
8
7
|
const extractIP_1 = __importDefault(require("./extractIP"));
|
|
9
8
|
const extractLocale_1 = __importDefault(require("./extractLocale"));
|
|
10
9
|
const index_1 = require("./index");
|
|
11
|
-
const
|
|
12
|
-
const ip = (0, extractIP_1.default)(req);
|
|
13
|
-
return await createSessionInfoBase(req.query, req.headers, ip, name, sessionInfo, props);
|
|
14
|
-
};
|
|
15
|
-
exports.createSessionInfoFromRequest = createSessionInfoFromRequest;
|
|
16
|
-
const createSessionInfoBase = async (querystrings, headers, ip, name, sessionInfo, props) => {
|
|
10
|
+
const createSessionInfoBase = async (querystrings, headers, ip, clientName, environment, sessionInfo, props) => {
|
|
17
11
|
const userId = querystrings.userId;
|
|
18
12
|
const userAgent = (0, buildUserAgentInfos_1.default)(headers['user-agent'], querystrings);
|
|
19
13
|
const client = {
|
|
20
14
|
...sessionInfo.client,
|
|
21
|
-
name,
|
|
15
|
+
name: clientName,
|
|
22
16
|
type: index_1.CLIENT_TYPE,
|
|
23
17
|
payload: {
|
|
24
18
|
...sessionInfo.client.payload,
|
|
@@ -41,12 +35,12 @@ const createSessionInfoBase = async (querystrings, headers, ip, name, sessionInf
|
|
|
41
35
|
const userInfos = await props.requestUserInfos(querystrings);
|
|
42
36
|
user = Object.assign({}, user, userInfos);
|
|
43
37
|
}
|
|
44
|
-
return { client, user, contexts };
|
|
38
|
+
return { client, user, contexts, environment };
|
|
45
39
|
};
|
|
46
|
-
const createSessionInfo = (socket,
|
|
40
|
+
const createSessionInfo = (socket, clientName, environment, sessionInfo, props) => async () => {
|
|
47
41
|
const request = socket.request;
|
|
48
42
|
const querystrings = socket.handshake.query;
|
|
49
43
|
const ip = (0, extractIP_1.default)(request);
|
|
50
|
-
return await createSessionInfoBase(querystrings, request.headers, ip,
|
|
44
|
+
return await createSessionInfoBase(querystrings, request.headers, ip, clientName, environment, sessionInfo, props);
|
|
51
45
|
};
|
|
52
46
|
exports.default = createSessionInfo;
|
|
@@ -50,9 +50,10 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
|
50
50
|
},
|
|
51
51
|
user: { id: 'my-user-id', displayName: 'my user', payload: {} },
|
|
52
52
|
contexts: [],
|
|
53
|
+
environment: 'PROD',
|
|
53
54
|
};
|
|
54
55
|
(0, globals_1.it)('without user payload', async () => {
|
|
55
|
-
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', defaultSessionInfo, {})();
|
|
56
|
+
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, {})();
|
|
56
57
|
// client
|
|
57
58
|
(0, globals_1.expect)(sessionInfo.client.name).toBe('my-client');
|
|
58
59
|
(0, globals_1.expect)(sessionInfo.client.type).toBe('webclient');
|
|
@@ -82,7 +83,7 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
|
82
83
|
const props = {
|
|
83
84
|
requestUserInfos,
|
|
84
85
|
};
|
|
85
|
-
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', defaultSessionInfo, props)();
|
|
86
|
+
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, props)();
|
|
86
87
|
(0, globals_1.expect)(sessionInfo.user.id).toBe('hans.muster@PRIMARY');
|
|
87
88
|
(0, globals_1.expect)(sessionInfo.user.displayName).toBe('Hans Muster');
|
|
88
89
|
(0, globals_1.expect)(sessionInfo.user.payload.username).toBe('hans.muster');
|
|
@@ -96,10 +97,11 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
|
96
97
|
const props = {
|
|
97
98
|
requestUserInfos,
|
|
98
99
|
};
|
|
99
|
-
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', defaultSessionInfo, props)();
|
|
100
|
+
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, props)();
|
|
100
101
|
(0, globals_1.expect)(sessionInfo.user.id).toBe('user-id');
|
|
101
102
|
(0, globals_1.expect)(sessionInfo.user.displayName).toBe('Webseiten Besucher');
|
|
102
103
|
(0, globals_1.expect)(sessionInfo.user.locale).toBe('de_DE');
|
|
103
104
|
(0, globals_1.expect)(sessionInfo.user.payload).toStrictEqual({});
|
|
105
|
+
(0, globals_1.expect)(sessionInfo.environment).toBe('TEST');
|
|
104
106
|
});
|
|
105
107
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Client, SessionInfoUser } from '@botfabrik/engine-core';
|
|
2
|
+
import type { Environment } from '@botfabrik/engine-domain';
|
|
2
3
|
import { Action } from '@botfabrik/engine-domain';
|
|
3
4
|
import { SpeechToTextProps } from './speechToText';
|
|
4
5
|
import type { SessionInfoUserPayload, WebclientMiddlewareState } from './types';
|
|
@@ -23,6 +24,6 @@ export declare enum Devices {
|
|
|
23
24
|
Desktop = "desktop",
|
|
24
25
|
None = "none"
|
|
25
26
|
}
|
|
26
|
-
declare const _default: (
|
|
27
|
+
declare const _default: (clientName: string, environment: Environment, props: WebClientProps) => Client<WebclientMiddlewareState>;
|
|
27
28
|
export default _default;
|
|
28
29
|
export declare const CLIENT_TYPE = "webclient";
|
package/dist/index.js
CHANGED
|
@@ -45,11 +45,11 @@ var Devices;
|
|
|
45
45
|
Devices["Desktop"] = "desktop";
|
|
46
46
|
Devices["None"] = "none";
|
|
47
47
|
})(Devices = exports.Devices || (exports.Devices = {}));
|
|
48
|
-
exports.default = (
|
|
48
|
+
exports.default = (clientName, environment, props) => async (bot) => {
|
|
49
49
|
const logger = bot.logger;
|
|
50
50
|
bot.webserver.express.enable('trust proxy');
|
|
51
51
|
bot.webserver.express.get('/', (_req, res) => {
|
|
52
|
-
res.redirect(`/${
|
|
52
|
+
res.redirect(`/${clientName}/embed`);
|
|
53
53
|
});
|
|
54
54
|
// serve transcript pdf
|
|
55
55
|
bot.webserver.express.use('/transcript-pdf/:sessionId', async (req, res) => {
|
|
@@ -66,14 +66,14 @@ exports.default = (name, props) => async (bot) => {
|
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
// serve embed resources
|
|
69
|
-
bot.webserver.express.get(`/${
|
|
70
|
-
const server = `${req.protocol}://${req.get('host')}/${
|
|
69
|
+
bot.webserver.express.get(`/${clientName}/embed`, (req, res) => {
|
|
70
|
+
const server = `${req.protocol}://${req.get('host')}/${clientName}`;
|
|
71
71
|
res.set('Content-Type', 'text/html; charset=utf-8');
|
|
72
72
|
res.write((0, views_1.default)(server, `${server}/embed/bundle.js`));
|
|
73
73
|
res.end();
|
|
74
74
|
});
|
|
75
75
|
if (!isFabVisible(props)) {
|
|
76
|
-
bot.webserver.express.get(`/${
|
|
76
|
+
bot.webserver.express.get(`/${clientName}/embed/bundle.js`, (req, res) => {
|
|
77
77
|
const caller = req.query['caller'];
|
|
78
78
|
if (caller === 'bookmarklet') {
|
|
79
79
|
res.sendFile(`${__dirname}/embed/bundle.js`);
|
|
@@ -85,23 +85,23 @@ exports.default = (name, props) => async (bot) => {
|
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
bot.webserver.express.use(`/${
|
|
88
|
+
bot.webserver.express.use(`/${clientName}/embed`, express.static(__dirname + '/embed', serveStaticOptions));
|
|
89
89
|
// serve chat client resources
|
|
90
|
-
bot.webserver.express.use(`/${
|
|
91
|
-
logger.info(`Webclient will be available on route: /${
|
|
92
|
-
const nsp = bot.webserver.socket.of(`/${
|
|
90
|
+
bot.webserver.express.use(`/${clientName}`, express.static(__dirname + '/client', serveStaticOptions));
|
|
91
|
+
logger.info(`Webclient will be available on route: /${clientName}`);
|
|
92
|
+
const nsp = bot.webserver.socket.of(`/${clientName}/chat`);
|
|
93
93
|
nsp.on('connection', async (socket) => {
|
|
94
94
|
try {
|
|
95
95
|
const querystrings = socket.handshake.query;
|
|
96
96
|
const sessionsCollection = bot.store.db.collection('sessions');
|
|
97
|
-
const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection,
|
|
97
|
+
const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection, clientName, props);
|
|
98
98
|
// create a channel for each session
|
|
99
99
|
socket.join(sessionId);
|
|
100
|
-
const sessionInfo = await (0, createSessionInfo_1.default)(socket,
|
|
100
|
+
const sessionInfo = await (0, createSessionInfo_1.default)(socket, clientName, environment, defaultSessionInfo, props)();
|
|
101
101
|
const session = await bot.createSession(sessionId, sessionInfo);
|
|
102
102
|
// sending active language and translations to client
|
|
103
103
|
const clientLocale = (0, getSupportedClientLocale_1.default)(session.translator.locale);
|
|
104
|
-
nsp.to(sessionId).emit('set-translations', clientLocale, bot.translation.getResourceBundle(clientLocale)[
|
|
104
|
+
nsp.to(sessionId).emit('set-translations', clientLocale, bot.translation.getResourceBundle(clientLocale)[clientName] || {});
|
|
105
105
|
// sending persisted state to client
|
|
106
106
|
const previousConversations = await (0, loadPreviousConversation_1.default)(bot.store, sessionId);
|
|
107
107
|
nsp.to(sessionId).emit('restore-client-state', { sessionId, messages: previousConversations });
|
|
@@ -172,8 +172,8 @@ exports.default = (name, props) => async (bot) => {
|
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
174
|
const client = {
|
|
175
|
-
name: `${
|
|
176
|
-
middleware: (0, middleware_1.default)(
|
|
175
|
+
name: `${clientName}Webclient`,
|
|
176
|
+
middleware: (0, middleware_1.default)(clientName, nsp),
|
|
177
177
|
};
|
|
178
178
|
return client;
|
|
179
179
|
};
|
|
@@ -6,5 +6,5 @@ interface SessionData {
|
|
|
6
6
|
sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>;
|
|
7
7
|
isNew: boolean;
|
|
8
8
|
}
|
|
9
|
-
declare const requestSessionData: (querystrings: any, sessionsCollection: any,
|
|
9
|
+
declare const requestSessionData: (querystrings: any, sessionsCollection: any, clientName: string, props: WebClientProps) => Promise<SessionData>;
|
|
10
10
|
export default requestSessionData;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const uuid_1 = require("uuid");
|
|
4
4
|
const index_1 = require("./index");
|
|
5
|
-
const requestSessionData = async (querystrings, sessionsCollection,
|
|
5
|
+
const requestSessionData = async (querystrings, sessionsCollection, clientName, props) => {
|
|
6
6
|
const baseQuery = {
|
|
7
7
|
'sessionInfo.client.type': index_1.CLIENT_TYPE,
|
|
8
|
-
'sessionInfo.client.name':
|
|
8
|
+
'sessionInfo.client.name': clientName,
|
|
9
9
|
};
|
|
10
10
|
let findSessionRecordQuery = { _id: querystrings.sessionId, ...baseQuery };
|
|
11
11
|
if (props.requestSessionRecordQuery) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botfabrik/engine-webclient",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.37.3",
|
|
4
4
|
"description": "Webclient for Botfabriks Bot Engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"prepublishOnly": "npm run build"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@botfabrik/engine-core": "^4.
|
|
22
|
-
"@botfabrik/engine-domain": "^4.
|
|
23
|
-
"@botfabrik/engine-transcript-export": "^4.
|
|
24
|
-
"@botfabrik/engine-utils": "^4.
|
|
21
|
+
"@botfabrik/engine-core": "^4.37.2",
|
|
22
|
+
"@botfabrik/engine-domain": "^4.37.2",
|
|
23
|
+
"@botfabrik/engine-transcript-export": "^4.37.2",
|
|
24
|
+
"@botfabrik/engine-utils": "^4.37.2",
|
|
25
25
|
"@google-cloud/speech": "^5.1.0",
|
|
26
26
|
"accept-language-parser": "^1.5.0",
|
|
27
27
|
"express": "^4.18.1",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"rimraf": "^3.0.2",
|
|
41
41
|
"typescript": "^4.8.3"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "81b633ae15a6ce846176fe354d27dbaa6835706f"
|
|
44
44
|
}
|