@botfabrik/engine-webclient 4.43.1 → 4.44.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.
@@ -9,7 +9,10 @@ const extractIP_1 = __importDefault(require("./extractIP"));
9
9
  (0, globals_1.it)('takes IP from x-forwarded-for header', () => {
10
10
  const request = {
11
11
  headers: { 'x-forwarded-for': '192.168.1.1, 192.168.1.1' },
12
- connection: { remoteAddress: '192.168.1.2', socket: { remoteAddress: '192.168.1.4' } },
12
+ connection: {
13
+ remoteAddress: '192.168.1.2',
14
+ socket: { remoteAddress: '192.168.1.4' },
15
+ },
13
16
  socket: { remoteAddress: '192.168.1.3' },
14
17
  };
15
18
  (0, globals_1.expect)((0, extractIP_1.default)(request)).toBe('192.168.1.1');
package/dist/index.js CHANGED
@@ -30,7 +30,6 @@ exports.CLIENT_TYPE = exports.Devices = void 0;
30
30
  const engine_domain_1 = require("@botfabrik/engine-domain");
31
31
  const engine_transcript_export_1 = require("@botfabrik/engine-transcript-export");
32
32
  const express = __importStar(require("express"));
33
- const mongodb_1 = require("mongodb");
34
33
  const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
35
34
  const getSupportedClientLocale_1 = __importDefault(require("./getSupportedClientLocale"));
36
35
  const loadPreviousConversation_1 = __importDefault(require("./loadPreviousConversation"));
@@ -102,10 +101,15 @@ exports.default = (clientName, environment, props) => async (bot) => {
102
101
  const session = await bot.createSession(sessionId, sessionInfo);
103
102
  // sending active language and translations to client
104
103
  const clientLocale = (0, getSupportedClientLocale_1.default)(session.translator.locale);
105
- nsp.to(sessionId).emit('set-translations', clientLocale, bot.translation.getResourceBundle(clientLocale)[clientName] || {});
104
+ nsp
105
+ .to(sessionId)
106
+ .emit('set-translations', clientLocale, bot.translation.getResourceBundle(clientLocale)[clientName] || {});
106
107
  // sending persisted state to client
107
108
  const previousConversations = await (0, loadPreviousConversation_1.default)(bot.store, sessionId);
108
- nsp.to(sessionId).emit('restore-client-state', { sessionId, messages: previousConversations });
109
+ nsp.to(sessionId).emit('restore-client-state', {
110
+ sessionId,
111
+ messages: previousConversations,
112
+ });
109
113
  // enable speech support
110
114
  if (props.speech) {
111
115
  nsp.to(sessionId).emit('enable-speech-support');
@@ -136,8 +140,12 @@ exports.default = (clientName, environment, props) => async (bot) => {
136
140
  if (isNew && props.getStartedAction) {
137
141
  await session.dispatch(props.getStartedAction);
138
142
  }
139
- if (isNew && props.expandChatWindowAtStart && props.expandChatWindowAtStart !== Devices.None) {
140
- nsp.to(session.id).emit('expand-window', { devices: props.expandChatWindowAtStart });
143
+ if (isNew &&
144
+ props.expandChatWindowAtStart &&
145
+ props.expandChatWindowAtStart !== Devices.None) {
146
+ nsp
147
+ .to(session.id)
148
+ .emit('expand-window', { devices: props.expandChatWindowAtStart });
141
149
  }
142
150
  // forward actions from webclient
143
151
  socket.on('action', async (action) => {
@@ -147,8 +155,13 @@ exports.default = (clientName, environment, props) => async (bot) => {
147
155
  await session.dispatch((0, engine_domain_1.guestDisconnected)(sessionId));
148
156
  });
149
157
  socket.on('conversation-rating', async (rating) => {
150
- sessionsCollection.updateOne({ _id: new mongodb_1.ObjectId(sessionId) }, { $set: { 'sessionInfo.client.payload.conversationRating': rating } });
151
- session.dispatch({ type: engine_domain_1.ActionTypes.CONVERSATION_RATING_FROM_GUEST, payload: { rating } });
158
+ sessionsCollection.updateOne({ _id: sessionId }, {
159
+ $set: { 'sessionInfo.client.payload.conversationRating': rating },
160
+ });
161
+ session.dispatch({
162
+ type: engine_domain_1.ActionTypes.CONVERSATION_RATING_FROM_GUEST,
163
+ payload: { rating },
164
+ });
152
165
  });
153
166
  socket.on('audio-message', async (buffer) => {
154
167
  if (props.speech) {
@@ -18,7 +18,9 @@ exports.default = (clientName, nsp) => async () => {
18
18
  const expandChatWindow = (action) => {
19
19
  const devices = action.payload?.devices;
20
20
  if (!!devices && devices !== __1.Devices.None) {
21
- nsp.to(session.id).emit('expand-window', { devices: action.payload.devices });
21
+ nsp
22
+ .to(session.id)
23
+ .emit('expand-window', { devices: action.payload.devices });
22
24
  }
23
25
  };
24
26
  const sessionInfo = session.getSessionInfo();
@@ -7,7 +7,10 @@ const requestSessionData = async (querystrings, sessionsCollection, clientName,
7
7
  'sessionInfo.client.type': index_1.CLIENT_TYPE,
8
8
  'sessionInfo.client.name': clientName,
9
9
  };
10
- let findSessionRecordQuery = { _id: querystrings.sessionId, ...baseQuery };
10
+ let findSessionRecordQuery = {
11
+ _id: querystrings.sessionId,
12
+ ...baseQuery,
13
+ };
11
14
  if (props.requestSessionRecordQuery) {
12
15
  const customQuery = await props.requestSessionRecordQuery(querystrings);
13
16
  findSessionRecordQuery = Object.assign({}, baseQuery, customQuery);
@@ -21,7 +21,11 @@ const requestSessionData_1 = __importDefault(require("./requestSessionData"));
21
21
  };
22
22
  const { sessionId, isNew } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection, 'test-bot', {});
23
23
  (0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
24
- (0, globals_1.expect)(findOne).toHaveBeenCalledWith({ _id: 'session-id', 'sessionInfo.client.name': 'test-bot', 'sessionInfo.client.type': 'webclient' }, { _id: 1, sessionInfo: 1 });
24
+ (0, globals_1.expect)(findOne).toHaveBeenCalledWith({
25
+ _id: 'session-id',
26
+ 'sessionInfo.client.name': 'test-bot',
27
+ 'sessionInfo.client.type': 'webclient',
28
+ }, { _id: 1, sessionInfo: 1 });
25
29
  (0, globals_1.expect)(sessionId).toBe('generated-uuid');
26
30
  (0, globals_1.expect)(isNew).toBe(true);
27
31
  });
@@ -33,7 +37,11 @@ const requestSessionData_1 = __importDefault(require("./requestSessionData"));
33
37
  };
34
38
  const { sessionId, isNew } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection, 'test-bot', {});
35
39
  (0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
36
- (0, globals_1.expect)(findOne).toHaveBeenCalledWith({ _id: 'session-id', 'sessionInfo.client.name': 'test-bot', 'sessionInfo.client.type': 'webclient' }, { _id: 1, sessionInfo: 1 });
40
+ (0, globals_1.expect)(findOne).toHaveBeenCalledWith({
41
+ _id: 'session-id',
42
+ 'sessionInfo.client.name': 'test-bot',
43
+ 'sessionInfo.client.type': 'webclient',
44
+ }, { _id: 1, sessionInfo: 1 });
37
45
  (0, globals_1.expect)(sessionId).toBe('session-id');
38
46
  (0, globals_1.expect)(isNew).toBe(false);
39
47
  });
@@ -16,7 +16,9 @@ const speechToText = (speechProps, locale, speechBytes) => {
16
16
  const audio = {
17
17
  content: speechBytes,
18
18
  };
19
- const phrases = speechProps.contextPhrases && speechProps.contextPhrases[locale] ? speechProps.contextPhrases[locale] : [];
19
+ const phrases = speechProps.contextPhrases && speechProps.contextPhrases[locale]
20
+ ? speechProps.contextPhrases[locale]
21
+ : [];
20
22
  const config = {
21
23
  encoding: 'LINEAR16',
22
24
  sampleRateHertz: 16000,
@@ -37,7 +39,8 @@ const speechToText = (speechProps, locale, speechBytes) => {
37
39
  .then((data) => {
38
40
  const response = data[0];
39
41
  const transcription = response?.results
40
- ?.map((result) => (result?.alternatives && result.alternatives[0]?.transcript) || '')
42
+ ?.map((result) => (result?.alternatives && result.alternatives[0]?.transcript) ||
43
+ '')
41
44
  .join('\n') || '';
42
45
  resolve(transcription);
43
46
  })
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
1
  {
2
- "name": "@botfabrik/engine-webclient",
3
- "version": "4.43.1",
4
- "description": "Webclient for Botfabriks Bot Engine",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "scripts": {
8
- "build": "npm run clean && npm run build:client && npm run build:server && npm run build:script-tag && npm run copy:client && npm run copy:script-tag",
9
- "build:script-tag": "(cd ./script-tag && npm run build && cd ..)",
10
- "build:client": "(cd ./client && npm run build && cd ..)",
11
- "build:server": "tsc",
12
- "copy:script-tag": "copyfiles -u 2 ./script-tag/dist/**/*.* ./dist/embed && copyfiles -u 2 ./script-tag/public/**/*.* ./dist/embed",
13
- "copy:client": "copyfiles -u 2 ./client/dist/** ./dist/client && copyfiles -u 2 ./client/dist/**/*.* ./dist/client",
14
- "clean": "rimraf ./dist",
15
- "test": "jest --verbose",
16
- "test:watch": "jest --watch",
17
- "prepare": "(cd client && npm install); (cd script-tag && npm install)",
18
- "prepublishOnly": "npm run build",
19
- "update": "npx npm-check-updates -i"
20
- },
21
- "dependencies": {
22
- "@botfabrik/engine-core": "^4.43.1",
23
- "@botfabrik/engine-domain": "^4.43.0",
24
- "@botfabrik/engine-transcript-export": "^4.43.1",
25
- "@botfabrik/engine-utils": "^4.43.0",
26
- "@google-cloud/speech": "^6.0.1",
27
- "accept-language-parser": "^1.5.0",
28
- "express": "^4.18.2",
29
- "mongodb": "^5.7.0",
30
- "socket.io": "4.7.2",
31
- "ua-parser-js": "^1.0.35",
32
- "uuid": "^9.0.0"
33
- },
34
- "devDependencies": {
35
- "@types/accept-language-parser": "^1.5.3",
36
- "@types/express": "^4.17.17",
37
- "@types/serve-static": "^1.15.2",
38
- "@types/ua-parser-js": "^0.7.36",
39
- "@types/uuid": "^9.0.2",
40
- "copyfiles": "^2.4.1",
41
- "rimraf": "^5.0.1",
42
- "typescript": "^5.1.6"
43
- },
44
- "gitHead": "a1c73f1b9ac587964a4d7487773bb3d631abab6a"
2
+ "name": "@botfabrik/engine-webclient",
3
+ "version": "4.44.1",
4
+ "description": "Webclient for Botfabriks Bot Engine",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "npm run clean && npm run build:client && npm run build:server && npm run build:script-tag && npm run copy:client && npm run copy:script-tag",
9
+ "build:script-tag": "(cd ./script-tag && npm run build && cd ..)",
10
+ "build:client": "(cd ./client && npm run build && cd ..)",
11
+ "build:server": "tsc",
12
+ "copy:script-tag": "copyfiles -u 2 ./script-tag/dist/**/*.* ./dist/embed && copyfiles -u 2 ./script-tag/public/**/*.* ./dist/embed",
13
+ "copy:client": "copyfiles -u 2 ./client/dist/** ./dist/client && copyfiles -u 2 ./client/dist/**/*.* ./dist/client",
14
+ "clean": "rimraf ./dist",
15
+ "test": "jest --verbose",
16
+ "test:watch": "jest --watch",
17
+ "prepare": "(cd client && npm install); (cd script-tag && npm install)",
18
+ "prepublishOnly": "npm run build",
19
+ "update": "npx npm-check-updates -i"
20
+ },
21
+ "dependencies": {
22
+ "@botfabrik/engine-core": "^4.44.1",
23
+ "@botfabrik/engine-domain": "^4.44.1",
24
+ "@botfabrik/engine-transcript-export": "^4.44.1",
25
+ "@botfabrik/engine-utils": "^4.44.1",
26
+ "@google-cloud/speech": "^6.0.1",
27
+ "accept-language-parser": "^1.5.0",
28
+ "express": "^4.18.2",
29
+ "mongodb": "^5.7.0",
30
+ "socket.io": "4.7.2",
31
+ "ua-parser-js": "^1.0.35",
32
+ "uuid": "^9.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/accept-language-parser": "^1.5.3",
36
+ "@types/express": "^4.17.17",
37
+ "@types/serve-static": "^1.15.2",
38
+ "@types/ua-parser-js": "^0.7.36",
39
+ "@types/uuid": "^9.0.2",
40
+ "copyfiles": "^2.4.1",
41
+ "rimraf": "^5.0.1",
42
+ "typescript": "^5.1.6"
43
+ },
44
+ "gitHead": "a456a925f1dfee04383963442401e03526f76596"
45
45
  }