@botfabrik/engine-webclient 4.68.0 → 4.69.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/README.md +77 -1
- package/dist/client/assets/index-C1QXALqF.css +1 -0
- package/dist/client/assets/index-DMj7jWAL.js +111 -0
- package/dist/client/assets/index-DMj7jWAL.js.map +1 -0
- package/dist/client/index.html +2 -2
- package/dist/createSessionInfo.d.ts +2 -1
- package/dist/createSessionInfo.js +5 -6
- package/dist/createSessionInfo.test.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -9
- package/package.json +2 -2
- package/dist/client/assets/index-Cg7Yy2hZ.js +0 -111
- package/dist/client/assets/index-Cg7Yy2hZ.js.map +0 -1
- package/dist/client/assets/index-DfppAcaS.css +0 -1
package/dist/client/index.html
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<meta name="theme-color" content="#000000" />
|
|
8
8
|
<meta name="google" content="notranslate" />
|
|
9
9
|
<title>Bubble Chat Client</title>
|
|
10
|
-
<script type="module" crossorigin src="./assets/index-
|
|
11
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
10
|
+
<script type="module" crossorigin src="./assets/index-DMj7jWAL.js"></script>
|
|
11
|
+
<link rel="stylesheet" crossorigin href="./assets/index-C1QXALqF.css">
|
|
12
12
|
</head>
|
|
13
13
|
|
|
14
14
|
<body>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { SessionInfo } from '@botfabrik/engine-core';
|
|
2
2
|
import type { Environment } from '@botfabrik/engine-domain';
|
|
3
|
+
import { ParsedUrlQuery } from 'node:querystring';
|
|
3
4
|
import type { Socket } from 'socket.io';
|
|
4
5
|
import { WebClientProps } from './index';
|
|
5
6
|
import type { SessionInfoClientPayload, SessionInfoUserPayload } from './types';
|
|
6
|
-
declare const createSessionInfo: (socket: Socket, clientName: string, environment: Environment, sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>, userId: string, locale: string | undefined, props: WebClientProps) => () => Promise<SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>>;
|
|
7
|
+
declare const createSessionInfo: (socket: Socket, clientName: string, environment: Environment, sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>, userId: string, locale: string | undefined, querystrings: ParsedUrlQuery, props: WebClientProps) => () => Promise<SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>>;
|
|
7
8
|
export default createSessionInfo;
|
|
@@ -14,16 +14,16 @@ const createSessionInfoBase = async (userId, querystrings, headers, ip, clientNa
|
|
|
14
14
|
type: index_1.CLIENT_TYPE,
|
|
15
15
|
payload: {
|
|
16
16
|
...sessionInfo.client.payload,
|
|
17
|
-
referrer: decodeURIComponent(querystrings['referrer'] || 'unknown'),
|
|
17
|
+
referrer: decodeURIComponent(querystrings['referrer'] || headers['referer'] || 'unknown'),
|
|
18
18
|
headers: { ...headers, cookie: undefined },
|
|
19
19
|
querystrings,
|
|
20
20
|
ip,
|
|
21
21
|
userAgent,
|
|
22
22
|
},
|
|
23
23
|
};
|
|
24
|
-
const firstName = querystrings
|
|
25
|
-
const lastName = querystrings
|
|
26
|
-
const email = querystrings
|
|
24
|
+
const firstName = querystrings['userFirstName'];
|
|
25
|
+
const lastName = querystrings['userLastName'];
|
|
26
|
+
const email = querystrings['userEmail'];
|
|
27
27
|
const displayName = firstName && lastName ? `${firstName} ${lastName}` : 'Webseiten Besucher';
|
|
28
28
|
let user = {
|
|
29
29
|
...sessionInfo.user,
|
|
@@ -42,9 +42,8 @@ const createSessionInfoBase = async (userId, querystrings, headers, ip, clientNa
|
|
|
42
42
|
}
|
|
43
43
|
return { client, user, contexts, environment };
|
|
44
44
|
};
|
|
45
|
-
const createSessionInfo = (socket, clientName, environment, sessionInfo, userId, locale, props) => async () => {
|
|
45
|
+
const createSessionInfo = (socket, clientName, environment, sessionInfo, userId, locale, querystrings, props) => async () => {
|
|
46
46
|
const request = socket.request;
|
|
47
|
-
const querystrings = socket.handshake.query;
|
|
48
47
|
const ip = (0, extractIP_1.default)(request);
|
|
49
48
|
return await createSessionInfoBase(userId, querystrings, request.headers, ip, clientName, environment, sessionInfo, locale, props);
|
|
50
49
|
};
|
|
@@ -55,7 +55,7 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
|
55
55
|
environment: 'PROD',
|
|
56
56
|
};
|
|
57
57
|
(0, globals_1.it)('without user payload', async () => {
|
|
58
|
-
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', {})();
|
|
58
|
+
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', { email: 'hans@example.com' }, {})();
|
|
59
59
|
// client
|
|
60
60
|
(0, globals_1.expect)(sessionInfo.client.name).toBe('my-client');
|
|
61
61
|
(0, globals_1.expect)(sessionInfo.client.type).toBe('webclient');
|
|
@@ -63,7 +63,7 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
|
63
63
|
...headers,
|
|
64
64
|
cookie: undefined,
|
|
65
65
|
}); // cookies sollen nicht gespeichert werden
|
|
66
|
-
(0, globals_1.expect)(sessionInfo.client.payload.querystrings).
|
|
66
|
+
(0, globals_1.expect)(sessionInfo.client.payload.querystrings.email).toBe('hans@example.com');
|
|
67
67
|
(0, globals_1.expect)(sessionInfo.client.payload.ip).toBe('151.248.213.117');
|
|
68
68
|
// user
|
|
69
69
|
(0, globals_1.expect)(sessionInfo.user.id).toBe('my-user-id');
|
|
@@ -88,7 +88,7 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
|
88
88
|
const props = {
|
|
89
89
|
requestUserInfos,
|
|
90
90
|
};
|
|
91
|
-
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', props)();
|
|
91
|
+
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', {}, props)();
|
|
92
92
|
(0, globals_1.expect)(sessionInfo.user.id).toBe('hans.muster@PRIMARY');
|
|
93
93
|
(0, globals_1.expect)(sessionInfo.user.displayName).toBe('Hans Muster');
|
|
94
94
|
(0, globals_1.expect)(sessionInfo.user.payload.username).toBe('hans.muster');
|
|
@@ -102,7 +102,7 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
|
102
102
|
const props = {
|
|
103
103
|
requestUserInfos,
|
|
104
104
|
};
|
|
105
|
-
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', props)();
|
|
105
|
+
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', {}, props)();
|
|
106
106
|
(0, globals_1.expect)(sessionInfo.user.id).toBe('my-user-id');
|
|
107
107
|
(0, globals_1.expect)(sessionInfo.user.displayName).toBe('Webseiten Besucher');
|
|
108
108
|
(0, globals_1.expect)(sessionInfo.user.locale).toBe('de_DE');
|
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface WebClientProps {
|
|
|
22
22
|
fabVisible?: boolean;
|
|
23
23
|
/**
|
|
24
24
|
* Displays a start screen before a new chat begins, useful for user opt-in (e.g., terms acceptance).
|
|
25
|
-
* Contains a text (`start-screen.
|
|
25
|
+
* Contains a text (`start-screen.intro` in Markdown), form fields, and a start button (`start-screen.start-chat`).
|
|
26
26
|
* No user data is collected until the user clicks the start button.
|
|
27
27
|
* @default false
|
|
28
28
|
*/
|
package/dist/index.js
CHANGED
|
@@ -101,6 +101,7 @@ exports.default = (clientName, environment, props) => async (bot) => {
|
|
|
101
101
|
try {
|
|
102
102
|
sendConfigurationToClient(socket, props, bot, clientName);
|
|
103
103
|
socket.on('start-chat', onStartChat(socket, props, bot, clientName, environment, logger));
|
|
104
|
+
socket.on('terminate-session', onTerminateSession(socket, bot));
|
|
104
105
|
}
|
|
105
106
|
catch (error) {
|
|
106
107
|
logger.error('Error while connecting webclient with backend.');
|
|
@@ -132,19 +133,20 @@ const serveStaticOptions = {
|
|
|
132
133
|
},
|
|
133
134
|
};
|
|
134
135
|
const isFabVisible = ({ fabVisible = true }) => fabVisible;
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
const
|
|
136
|
+
const onTerminateSession = (socket, bot) => async ({ sessionId, // passed if the user wants to restart the chat
|
|
137
|
+
}) => {
|
|
138
|
+
const session = await bot.createSession(sessionId);
|
|
139
|
+
socket.leave(sessionId);
|
|
140
|
+
await session.dispatch((0, engine_domain_1.guestDisconnected)(sessionId));
|
|
141
|
+
};
|
|
142
|
+
const onStartChat = (socket, props, bot, clientName, environment, logger) => async ({ sessionId: sessionIdFromClient, userId: defaultUserId, querystrings, }) => {
|
|
143
|
+
const locale = (0, extractLocale_1.default)(querystrings, socket.request.headers['accept-language']);
|
|
138
144
|
const sessionsCollection = bot.store.db.collection('sessions');
|
|
139
|
-
const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await (0, requestSessionData_1.default)(sessionIdFromClient,
|
|
145
|
+
const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await (0, requestSessionData_1.default)(sessionIdFromClient, querystrings, sessionsCollection, clientName, locale, props);
|
|
140
146
|
// create a channel for each session
|
|
141
147
|
socket.join(sessionId);
|
|
142
|
-
const sessionInfo = await (0, createSessionInfo_1.default)(socket, clientName, environment, defaultSessionInfo, defaultUserId, locale, props)();
|
|
148
|
+
const sessionInfo = await (0, createSessionInfo_1.default)(socket, clientName, environment, defaultSessionInfo, defaultUserId, locale, querystrings, props)();
|
|
143
149
|
const session = await bot.createSession(sessionId, sessionInfo);
|
|
144
|
-
if (sessionIdToTerminate) {
|
|
145
|
-
socket.leave(sessionIdToTerminate);
|
|
146
|
-
await session.dispatch((0, engine_domain_1.guestDisconnected)(sessionIdToTerminate));
|
|
147
|
-
}
|
|
148
150
|
// sending persisted state to client
|
|
149
151
|
const previousConversations = await (0, loadPreviousConversation_1.default)(bot.store, sessionId);
|
|
150
152
|
socket.emit('restore-client-state', {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botfabrik/engine-webclient",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.69.0",
|
|
4
4
|
"description": "Webclient for Botfabriks Bot Engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"tsx": "^4.16.3",
|
|
41
41
|
"typescript": "5.1.6"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "9560b9553e1db53d1a6f812788a32b9169701ca3"
|
|
44
44
|
}
|