@botfabrik/engine-webclient 4.67.3 → 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.
@@ -3,6 +3,9 @@
3
3
  * Dazu kann eine eigene CSS Datei namens 'custom.css' im Verzeichnis 'public/${name-meines-webclients}/' abgelegt werden.
4
4
  */
5
5
 
6
+ /* import design set in cms */
7
+ @import url('/cms/chatbot/design/styles.css');
8
+
6
9
  @import url(//fonts.googleapis.com/css?family=Roboto:400,300,700,500,100,200);
7
10
 
8
11
  .bubble-chat {
@@ -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-Cg7Yy2hZ.js"></script>
11
- <link rel="stylesheet" crossorigin href="./assets/index-DfppAcaS.css">
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.userFirstName;
25
- const lastName = querystrings.userLastName;
26
- const email = querystrings.userEmail;
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).toEqual(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.body` in Markdown) and a start button (`start-screen.start-chat`).
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
@@ -84,6 +84,15 @@ exports.default = (clientName, environment, props) => async (bot) => {
84
84
  });
85
85
  }
86
86
  bot.webserver.express.use(`/${clientName}/embed`, express.static(__dirname + '/embed', serveStaticOptions));
87
+ bot.webserver.express.get(`/${clientName}/logo.svg`, (_req, res) => {
88
+ res.redirect(`/cms/chatbot/design/logo.svg?client=${clientName}`);
89
+ });
90
+ bot.webserver.express.get(`/${clientName}/bot.svg`, (_req, res) => {
91
+ res.redirect(`/cms/chatbot/design/bot.svg?client=${clientName}`);
92
+ });
93
+ bot.webserver.express.get(`/${clientName}/fab.svg`, (_req, res) => {
94
+ res.redirect(`/cms/chatbot/design/fab.svg?client=${clientName}`);
95
+ });
87
96
  // serve chat client resources
88
97
  bot.webserver.express.use(`/${clientName}`, express.static(__dirname + '/client', serveStaticOptions));
89
98
  logger.info(`Webclient will be available on route: /${clientName}`);
@@ -92,6 +101,7 @@ exports.default = (clientName, environment, props) => async (bot) => {
92
101
  try {
93
102
  sendConfigurationToClient(socket, props, bot, clientName);
94
103
  socket.on('start-chat', onStartChat(socket, props, bot, clientName, environment, logger));
104
+ socket.on('terminate-session', onTerminateSession(socket, bot));
95
105
  }
96
106
  catch (error) {
97
107
  logger.error('Error while connecting webclient with backend.');
@@ -123,19 +133,20 @@ const serveStaticOptions = {
123
133
  },
124
134
  };
125
135
  const isFabVisible = ({ fabVisible = true }) => fabVisible;
126
- const onStartChat = (socket, props, bot, clientName, environment, logger) => async ({ sessionId: sessionIdFromClient, sessionIdToTerminate, // passed if the user wants to restart the chat
127
- userId: defaultUserId, }) => {
128
- const locale = (0, extractLocale_1.default)(socket.handshake.query, socket.request.headers['accept-language']);
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']);
129
144
  const sessionsCollection = bot.store.db.collection('sessions');
130
- const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await (0, requestSessionData_1.default)(sessionIdFromClient, socket.handshake.query, sessionsCollection, clientName, locale, props);
145
+ const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await (0, requestSessionData_1.default)(sessionIdFromClient, querystrings, sessionsCollection, clientName, locale, props);
131
146
  // create a channel for each session
132
147
  socket.join(sessionId);
133
- 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)();
134
149
  const session = await bot.createSession(sessionId, sessionInfo);
135
- if (sessionIdToTerminate) {
136
- socket.leave(sessionIdToTerminate);
137
- await session.dispatch((0, engine_domain_1.guestDisconnected)(sessionIdToTerminate));
138
- }
139
150
  // sending persisted state to client
140
151
  const previousConversations = await (0, loadPreviousConversation_1.default)(bot.store, sessionId);
141
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.67.3",
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": "e6096ac13c97e41197a69c861569d21a115a9343"
43
+ "gitHead": "9560b9553e1db53d1a6f812788a32b9169701ca3"
44
44
  }