@xapp/stentor-gbm 1.44.25 → 1.44.27

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/lib/Channel.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
+ /*! Copyright (c) 2022, XAPPmedia */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.GoogleBusinessMessages = exports.GOOGLE_BUSINESS_MESSAGE_CHANNEL = exports.capabilities = void 0;
4
5
  const Constants_1 = require("./Constants");
5
6
  const Guards_1 = require("./Guards");
6
7
  const GbmHandlerHook_1 = require("./GbmHandlerHook");
7
8
  const Translators_1 = require("./Translators");
9
+ const PreResponseHook_1 = require("./PreResponseHook");
8
10
  function capabilities(_body) {
9
11
  return {
10
12
  channel: Constants_1.GOOGLE_BUSINESS_MESSAGES_PLATFORM,
@@ -16,7 +18,7 @@ function capabilities(_body) {
16
18
  canThrowCard: true,
17
19
  hasScreen: true,
18
20
  canTransferCall: true,
19
- hasWebBrowser: true
21
+ hasWebBrowser: true,
20
22
  };
21
23
  }
22
24
  exports.capabilities = capabilities;
@@ -26,17 +28,23 @@ exports.GOOGLE_BUSINESS_MESSAGE_CHANNEL = {
26
28
  handlerHook: GbmHandlerHook_1.handlerHook,
27
29
  request: new Translators_1.TranslateRequest(),
28
30
  response: new Translators_1.TranslateResponse(),
29
- capabilities
31
+ capabilities,
30
32
  };
31
33
  function GoogleBusinessMessages(nlu, props) {
32
34
  const defaultProps = {
33
35
  botAvatarName: "Bot",
34
36
  botAvatarImageUrl: "https://storage.googleapis.com/sample-avatars-for-bm/bot-avatar.jpg",
35
37
  sessionAgeMs: -1,
36
- sessionRegex: new RegExp("^hello$|^Hello$|^Reset$|^reset$")
38
+ sessionRegex: new RegExp("^[hH]ello$|^[rR]eset$"),
37
39
  };
38
40
  const finalProps = Object.assign(Object.assign({}, defaultProps), props);
39
- return Object.assign(Object.assign({}, exports.GOOGLE_BUSINESS_MESSAGE_CHANNEL), { response: new Translators_1.TranslateResponse(finalProps), handlerHook: GbmHandlerHook_1.handlerHook.bind({ props: finalProps }), nlu });
41
+ const channel = Object.assign(Object.assign({}, exports.GOOGLE_BUSINESS_MESSAGE_CHANNEL), { response: new Translators_1.TranslateResponse(finalProps), handlerHook: GbmHandlerHook_1.handlerHook.bind({ props: finalProps }), nlu });
42
+ if (!!nlu && typeof nlu.setContext === "function") {
43
+ channel.hooks = {
44
+ preResponseTranslation: (0, PreResponseHook_1.preResponseHook)(nlu),
45
+ };
46
+ }
47
+ return channel;
40
48
  }
41
49
  exports.GoogleBusinessMessages = GoogleBusinessMessages;
42
50
  //# sourceMappingURL=Channel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Channel.js","sourceRoot":"","sources":["../src/Channel.ts"],"names":[],"mappings":";;;AAGA,2CAAgE;AAChE,qCAAwC;AACxC,qDAA+C;AAC/C,+CAAoE;AASpE,SAAgB,YAAY,CAAC,KAAa;IACtC,OAAO;QACH,OAAO,EAAE,6CAAiC;QAC1C,cAAc,EAAE,KAAK;QACrB,YAAY,EAAE,KAAK;QACnB,cAAc,EAAE,IAAI;QACpB,YAAY,EAAE,KAAK;QACnB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,eAAe,EAAE,IAAI;QACrB,aAAa,EAAE,IAAI;KACtB,CAAC;AACN,CAAC;AAbD,oCAaC;AAEY,QAAA,+BAA+B,GAAY;IACpD,IAAI,EAAE,6CAAiC;IACvC,IAAI,EAAE,qBAAY;IAClB,WAAW,EAAX,4BAAW;IACX,OAAO,EAAE,IAAI,8BAAgB,EAAE;IAC/B,QAAQ,EAAE,IAAI,+BAAiB,EAAE;IACjC,YAAY;CACf,CAAC;AAEF,SAAgB,sBAAsB,CAAC,GAAe,EAAE,KAAuB;IAC3E,MAAM,YAAY,GAAoB;QAClC,aAAa,EAAE,KAAK;QACpB,iBAAiB,EAAE,qEAAqE;QACxF,YAAY,EA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AAC;IAEF,MAAM,UAAU,mCAAQ,YAAY,GAAK,KAAK,CAAE,CAAC;IAEjD,MAAM,OAAO,mCACN,uCAA+B,KAClC,QAAQ,EAAE,IAAI,+BAAiB,CAAC,UAAU,CAAC,EAC3C,WAAW,EAAE,4BAAW,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EACpD,GAAG,GACN,CAAC;IAEF,IAAI,CAAC,CAAC,GAAG,IAAI,OAAO,GAAG,CAAC,UAAU,KAAK,UAAU,EAAE;QAC/C,OAAO,CAAC,KAAK,GAAG;YACZ,sBAAsB,EAAE,IAAA,iCAAe,EAAC,GAAG,CAAC;SAC/C,CAAC;KACL;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAxBD,wDAwBC"}
@@ -0,0 +1,16 @@
1
+ /*! Copyright (c) 2023, XAPP AI */
2
+ import { AbstractResponseBuilder, NLUService, Request, Storage } from "stentor-models";
3
+ export type PreResponseHook = (request: Request, response: AbstractResponseBuilder, storage: Storage) => Promise<{
4
+ request: Request;
5
+ response: AbstractResponseBuilder;
6
+ storage: Storage;
7
+ }>;
8
+ /**
9
+ * Called right before we send the response.
10
+ *
11
+ * This is currently used to set the context on the nlu if we have any active contexts.
12
+ *
13
+ * @param nlu - Required to update the active context
14
+ * @returns
15
+ */
16
+ export declare function preResponseHook(nlu: NLUService): PreResponseHook;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2023, XAPP AI */
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.preResponseHook = void 0;
14
+ const stentor_guards_1 = require("stentor-guards");
15
+ const stentor_logger_1 = require("stentor-logger");
16
+ const stentor_utils_1 = require("stentor-utils");
17
+ /**
18
+ * Called right before we send the response.
19
+ *
20
+ * This is currently used to set the context on the nlu if we have any active contexts.
21
+ *
22
+ * @param nlu - Required to update the active context
23
+ * @returns
24
+ */
25
+ function preResponseHook(nlu) {
26
+ return function preResponseHook(request, response, storage) {
27
+ var _a, _b;
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ if ((0, stentor_guards_1.hasSessionId)(request)) {
30
+ const resp = response.response;
31
+ const sessionId = request.sessionId;
32
+ if ((0, stentor_utils_1.existsAndNotEmpty)((_a = resp.context) === null || _a === void 0 ? void 0 : _a.active) && typeof (nlu === null || nlu === void 0 ? void 0 : nlu.setContext) === "function") {
33
+ const debug = resp.context.active.reduce((prev, current) => {
34
+ return `${prev} ${current.name} turns: ${current.timeToLive.turnsToLive}`;
35
+ }, "");
36
+ (0, stentor_logger_1.log)().info(`GBM: Sending active context for session ${sessionId}: ${debug}`);
37
+ yield nlu.setContext({
38
+ userId: request.userId,
39
+ sessionId,
40
+ activeContext: (_b = resp.context) === null || _b === void 0 ? void 0 : _b.active,
41
+ });
42
+ }
43
+ }
44
+ return { request, response, storage };
45
+ });
46
+ };
47
+ }
48
+ exports.preResponseHook = preResponseHook;
49
+ //# sourceMappingURL=PreResponseHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PreResponseHook.js","sourceRoot":"","sources":["../src/PreResponseHook.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;AAElC,mDAA8C;AAC9C,mDAAqC;AAErC,iDAAkD;AAYlD;;;;;;;GAOG;AACH,SAAgB,eAAe,CAAC,GAAe;IAC3C,OAAO,SAAe,eAAe,CACjC,OAAgB,EAChB,QAAiC,EACjC,OAAgB;;;YAMhB,IAAI,IAAA,6BAAY,EAAC,OAAO,CAAC,EAAE;gBACvB,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC;gBAC/B,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;gBAEpC,IAAI,IAAA,iCAAiB,EAAC,MAAA,IAAI,CAAC,OAAO,0CAAE,MAAM,CAAC,IAAI,OAAO,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,CAAA,KAAK,UAAU,EAAE;oBAClF,MAAM,KAAK,GAAW,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;wBAC/D,OAAO,GAAG,IAAI,IAAI,OAAO,CAAC,IAAI,WAAW,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;oBAC9E,CAAC,EAAE,EAAE,CAAC,CAAC;oBACP,IAAA,oBAAG,GAAE,CAAC,IAAI,CAAC,2CAA2C,SAAS,KAAK,KAAK,EAAE,CAAC,CAAC;oBAE7E,MAAM,GAAG,CAAC,UAAU,CAAC;wBACjB,MAAM,EAAE,OAAO,CAAC,MAAM;wBACtB,SAAS;wBACT,aAAa,EAAE,MAAA,IAAI,CAAC,OAAO,0CAAE,MAAM;qBACtC,CAAC,CAAC;iBACN;aACJ;YAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;;KACzC,CAAC;AACN,CAAC;AA9BD,0CA8BC"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "1.44.25",
7
+ "version": "1.44.27",
8
8
  "description": "Google Business Messages channel for stentor",
9
9
  "types": "lib/index",
10
10
  "main": "lib/index",
@@ -26,24 +26,24 @@
26
26
  "mocha": "10.2.0",
27
27
  "sinon": "15.0.1",
28
28
  "sinon-chai": "3.7.0",
29
- "stentor-constants": "1.57.65",
30
- "stentor-guards": "1.57.65",
31
- "stentor-interaction-model": "1.57.66",
32
- "stentor-locales": "1.57.66",
33
- "stentor-logger": "1.57.66",
34
- "stentor-media": "1.57.66",
35
- "stentor-models": "1.57.65",
36
- "stentor-request": "1.57.66",
37
- "stentor-response": "1.57.66",
38
- "stentor-utils": "1.57.66",
29
+ "stentor-constants": "1.57.68",
30
+ "stentor-guards": "1.57.68",
31
+ "stentor-interaction-model": "1.57.68",
32
+ "stentor-locales": "1.57.68",
33
+ "stentor-logger": "1.57.68",
34
+ "stentor-media": "1.57.68",
35
+ "stentor-models": "1.57.68",
36
+ "stentor-request": "1.57.68",
37
+ "stentor-response": "1.57.68",
38
+ "stentor-utils": "1.57.68",
39
39
  "ts-node": "10.9.1",
40
40
  "typescript": "4.9.5",
41
41
  "uuid": "9.0.0"
42
42
  },
43
43
  "dependencies": {
44
44
  "@xapp/patterns": "2.0.1",
45
- "@xapp/stentor-actions-on-google": "1.44.23",
46
- "@xapp/stentor-app": "1.44.23",
45
+ "@xapp/stentor-actions-on-google": "1.44.27",
46
+ "@xapp/stentor-app": "1.44.27",
47
47
  "businessmessages": "1.0.4",
48
48
  "google-auth-library": "8.7.0",
49
49
  "googleapis-common": "6.0.4",
@@ -66,5 +66,5 @@
66
66
  "clean": "rm -rf ./lib/*",
67
67
  "test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
68
68
  },
69
- "gitHead": "d10bb6ec9caede05cc0e0d4d5769cc7848e3d576"
69
+ "gitHead": "d594e45fd2901c1f061f95cad900c7dcf2fed431"
70
70
  }