@aws-amplify/interactions 4.0.49 → 4.0.50-unstable.4

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.
Files changed (39) hide show
  1. package/dist/aws-amplify-interactions.js +177 -88
  2. package/dist/aws-amplify-interactions.js.map +1 -1
  3. package/dist/aws-amplify-interactions.min.js +1 -1
  4. package/dist/aws-amplify-interactions.min.js.map +1 -1
  5. package/lib/Interactions.d.ts +2 -2
  6. package/lib/Interactions.js +45 -25
  7. package/lib/Interactions.js.map +1 -1
  8. package/lib/Providers/AWSLexProvider.d.ts +5 -3
  9. package/lib/Providers/AWSLexProvider.js +95 -61
  10. package/lib/Providers/AWSLexProvider.js.map +1 -1
  11. package/lib/index.d.ts +1 -0
  12. package/lib/index.js +1 -0
  13. package/lib/index.js.map +1 -1
  14. package/lib/types/Provider.d.ts +2 -1
  15. package/lib/types/Providers/AWSLexProvider.d.ts +10 -0
  16. package/lib/types/Providers/AWSLexProvider.js +3 -0
  17. package/lib/types/Providers/AWSLexProvider.js.map +1 -0
  18. package/lib/types/index.d.ts +1 -0
  19. package/lib-esm/Interactions.d.ts +2 -2
  20. package/lib-esm/Interactions.js +45 -25
  21. package/lib-esm/Interactions.js.map +1 -1
  22. package/lib-esm/Providers/AWSLexProvider.d.ts +5 -3
  23. package/lib-esm/Providers/AWSLexProvider.js +95 -61
  24. package/lib-esm/Providers/AWSLexProvider.js.map +1 -1
  25. package/lib-esm/index.d.ts +1 -0
  26. package/lib-esm/index.js +1 -0
  27. package/lib-esm/index.js.map +1 -1
  28. package/lib-esm/types/Provider.d.ts +2 -1
  29. package/lib-esm/types/Providers/AWSLexProvider.d.ts +10 -0
  30. package/lib-esm/types/Providers/AWSLexProvider.js +1 -0
  31. package/lib-esm/types/Providers/AWSLexProvider.js.map +1 -0
  32. package/lib-esm/types/index.d.ts +1 -0
  33. package/package.json +3 -3
  34. package/src/Interactions.ts +53 -29
  35. package/src/Providers/AWSLexProvider.ts +48 -11
  36. package/src/index.ts +1 -0
  37. package/src/types/Provider.ts +1 -1
  38. package/src/types/Providers/AWSLexProvider.ts +11 -0
  39. package/src/types/index.ts +1 -0
@@ -11207,6 +11207,10 @@ function () {
11207
11207
  * @param {InteractionsOptions} options - Configuration object for Interactions
11208
11208
  */
11209
11209
  function InteractionsClass(options) {
11210
+ if (options === void 0) {
11211
+ options = {};
11212
+ }
11213
+
11210
11214
  this._options = options;
11211
11215
  logger.debug('Interactions Options', this._options);
11212
11216
  this._pluggables = {};
@@ -11218,7 +11222,7 @@ function () {
11218
11222
  /**
11219
11223
  *
11220
11224
  * @param {InteractionsOptions} options - Configuration object for Interactions
11221
- * @return {Object} - The current configuration
11225
+ * @return {InteractionsOptions} - The current configuration
11222
11226
  */
11223
11227
 
11224
11228
 
@@ -11242,32 +11246,50 @@ function () {
11242
11246
  _this._options.bots[bot.name] = bot;
11243
11247
  });
11244
11248
  }
11245
- } // Check if AWSLex provider is already on pluggables
11249
+ } // configure bots to their specific providers
11246
11250
 
11247
11251
 
11248
- if (!this._pluggables.AWSLexProvider && bots_config && Object.keys(bots_config).map(function (key) {
11249
- return bots_config[key];
11250
- }).find(function (bot) {
11251
- return !bot.providerName || bot.providerName === 'AWSLexProvider';
11252
- })) {
11253
- this._pluggables.AWSLexProvider = new _Providers__WEBPACK_IMPORTED_MODULE_1__["AWSLexProvider"]();
11254
- }
11252
+ Object.keys(bots_config).forEach(function (botKey) {
11253
+ var _a;
11254
+
11255
+ var bot = bots_config[botKey];
11256
+ var providerName = bot.providerName || 'AWSLexProvider'; // add default provider if required
11257
+
11258
+ if (!_this._pluggables.AWSLexProvider && providerName === 'AWSLexProvider') {
11259
+ _this._pluggables.AWSLexProvider = new _Providers__WEBPACK_IMPORTED_MODULE_1__["AWSLexProvider"]();
11260
+ } // configure bot with it's respective provider
11261
+
11255
11262
 
11256
- Object.keys(this._pluggables).map(function (key) {
11257
- _this._pluggables[key].configure(_this._options.bots);
11263
+ if (_this._pluggables[providerName]) {
11264
+ _this._pluggables[providerName].configure((_a = {}, _a[bot.name] = bot, _a));
11265
+ } else {
11266
+ logger.debug("bot " + bot.name + " was not configured as " + providerName + " provider was not found");
11267
+ }
11258
11268
  });
11259
11269
  return this._options;
11260
11270
  };
11261
11271
 
11262
11272
  InteractionsClass.prototype.addPluggable = function (pluggable) {
11263
- if (pluggable && pluggable.getCategory() === 'Interactions') {
11264
- if (!this._pluggables[pluggable.getProviderName()]) {
11265
- pluggable.configure(this._options.bots);
11266
- this._pluggables[pluggable.getProviderName()] = pluggable;
11267
- return;
11268
- } else {
11269
- throw new Error('Bot ' + pluggable.getProviderName() + ' already plugged');
11270
- }
11273
+ var _this = this;
11274
+
11275
+ if (!(pluggable && pluggable.getCategory() === 'Interactions')) {
11276
+ throw new Error('Invalid pluggable');
11277
+ }
11278
+
11279
+ if (!this._pluggables[pluggable.getProviderName()]) {
11280
+ // configure bots for the new plugin
11281
+ Object.keys(this._options.bots).filter(function (botKey) {
11282
+ return _this._options.bots[botKey].providerName === pluggable.getProviderName();
11283
+ }).forEach(function (botKey) {
11284
+ var _a;
11285
+
11286
+ var bot = _this._options.bots[botKey];
11287
+ pluggable.configure((_a = {}, _a[bot.name] = bot, _a));
11288
+ });
11289
+ this._pluggables[pluggable.getProviderName()] = pluggable;
11290
+ return;
11291
+ } else {
11292
+ throw new Error('Pluggable ' + pluggable.getProviderName() + ' already plugged');
11271
11293
  }
11272
11294
  };
11273
11295
 
@@ -11278,13 +11300,17 @@ function () {
11278
11300
  switch (_a.label) {
11279
11301
  case 0:
11280
11302
  if (!this._options.bots || !this._options.bots[botname]) {
11281
- throw new Error('Bot ' + botname + ' does not exist');
11303
+ return [2
11304
+ /*return*/
11305
+ , Promise.reject('Bot ' + botname + ' does not exist')];
11282
11306
  }
11283
11307
 
11284
11308
  botProvider = this._options.bots[botname].providerName || 'AWSLexProvider';
11285
11309
 
11286
11310
  if (!this._pluggables[botProvider]) {
11287
- throw new Error('Bot ' + botProvider + ' does not have valid pluggin did you try addPluggable first?');
11311
+ return [2
11312
+ /*return*/
11313
+ , Promise.reject('Bot ' + botProvider + ' does not have valid pluggin did you try addPluggable first?')];
11288
11314
  }
11289
11315
 
11290
11316
  return [4
@@ -11318,7 +11344,7 @@ function () {
11318
11344
  }();
11319
11345
 
11320
11346
 
11321
- var Interactions = new InteractionsClass(null);
11347
+ var Interactions = new InteractionsClass();
11322
11348
  _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["Amplify"].register(Interactions);
11323
11349
 
11324
11350
  /***/ }),
@@ -11338,18 +11364,6 @@ __webpack_require__.r(__webpack_exports__);
11338
11364
  /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
11339
11365
  /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_2__);
11340
11366
  /* harmony import */ var _AWSLexProviderHelper_convert__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./AWSLexProviderHelper/convert */ "./lib-esm/Providers/AWSLexProviderHelper/convert.js");
11341
- /*
11342
- * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
11343
- *
11344
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
11345
- * the License. A copy of the License is located at
11346
- *
11347
- * http://aws.amazon.com/apache2.0/
11348
- *
11349
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11350
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11351
- * and limitations under the License.
11352
- */
11353
11367
  var __extends = undefined && undefined.__extends || function () {
11354
11368
  var _extendStatics = function extendStatics(d, b) {
11355
11369
  _extendStatics = Object.setPrototypeOf || {
@@ -11534,6 +11548,19 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
11534
11548
  };
11535
11549
  }
11536
11550
  };
11551
+ /*
11552
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
11553
+ *
11554
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
11555
+ * the License. A copy of the License is located at
11556
+ *
11557
+ * http://aws.amazon.com/apache2.0/
11558
+ *
11559
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11560
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11561
+ * and limitations under the License.
11562
+ */
11563
+
11537
11564
 
11538
11565
 
11539
11566
 
@@ -11561,6 +11588,24 @@ function (_super) {
11561
11588
  return 'AWSLexProvider';
11562
11589
  };
11563
11590
 
11591
+ AWSLexProvider.prototype.configure = function (config) {
11592
+ if (config === void 0) {
11593
+ config = {};
11594
+ }
11595
+
11596
+ var propertiesToTest = ['name', 'alias', 'region'];
11597
+ Object.keys(config).forEach(function (botKey) {
11598
+ var botConfig = config[botKey]; // is bot config correct
11599
+
11600
+ if (!propertiesToTest.every(function (x) {
11601
+ return x in botConfig;
11602
+ })) {
11603
+ throw new Error('invalid bot configuration');
11604
+ }
11605
+ });
11606
+ return _super.prototype.configure.call(this, config);
11607
+ };
11608
+
11564
11609
  AWSLexProvider.prototype.reportBotStatus = function (data, botname) {
11565
11610
  var _this = this; // Check if state is fulfilled to resolve onFullfilment promise
11566
11611
 
@@ -11602,29 +11647,40 @@ function (_super) {
11602
11647
 
11603
11648
  AWSLexProvider.prototype.sendMessage = function (botname, message) {
11604
11649
  return __awaiter(this, void 0, void 0, function () {
11605
- var credentials, params, postTextCommand, data, err_1, content, messageType, postContentCommand, data, audioArray, err_2;
11606
- return __generator(this, function (_a) {
11607
- switch (_a.label) {
11650
+ var credentials, error_1, params, postTextCommand, data, err_1, content, messageType, _a, postContentCommand, data, audioArray, _b, err_2;
11651
+
11652
+ return __generator(this, function (_c) {
11653
+ switch (_c.label) {
11608
11654
  case 0:
11655
+ // check if bot exists
11609
11656
  if (!this._config[botname]) {
11610
11657
  return [2
11611
11658
  /*return*/
11612
11659
  , Promise.reject('Bot ' + botname + ' does not exist')];
11613
11660
  }
11614
11661
 
11662
+ _c.label = 1;
11663
+
11664
+ case 1:
11665
+ _c.trys.push([1, 3,, 4]);
11666
+
11615
11667
  return [4
11616
11668
  /*yield*/
11617
11669
  , _aws_amplify_core__WEBPACK_IMPORTED_MODULE_2__["Credentials"].get()];
11618
11670
 
11619
- case 1:
11620
- credentials = _a.sent();
11671
+ case 2:
11672
+ credentials = _c.sent();
11673
+ return [3
11674
+ /*break*/
11675
+ , 4];
11621
11676
 
11622
- if (!credentials) {
11623
- return [2
11624
- /*return*/
11625
- , Promise.reject('No credentials')];
11626
- }
11677
+ case 3:
11678
+ error_1 = _c.sent();
11679
+ return [2
11680
+ /*return*/
11681
+ , Promise.reject('No credentials')];
11627
11682
 
11683
+ case 4:
11628
11684
  this.lexRuntimeServiceClient = new _aws_sdk_client_lex_runtime_service__WEBPACK_IMPORTED_MODULE_1__["LexRuntimeServiceClient"]({
11629
11685
  region: this._config[botname].region,
11630
11686
  credentials: credentials,
@@ -11632,7 +11688,7 @@ function (_super) {
11632
11688
  });
11633
11689
  if (!(typeof message === 'string')) return [3
11634
11690
  /*break*/
11635
- , 6];
11691
+ , 9];
11636
11692
  params = {
11637
11693
  botAlias: this._config[botname].alias,
11638
11694
  botName: botname,
@@ -11640,76 +11696,104 @@ function (_super) {
11640
11696
  userId: credentials.identityId
11641
11697
  };
11642
11698
  logger.debug('postText to lex', message);
11643
- _a.label = 2;
11699
+ _c.label = 5;
11644
11700
 
11645
- case 2:
11646
- _a.trys.push([2, 4,, 5]);
11701
+ case 5:
11702
+ _c.trys.push([5, 7,, 8]);
11647
11703
 
11648
11704
  postTextCommand = new _aws_sdk_client_lex_runtime_service__WEBPACK_IMPORTED_MODULE_1__["PostTextCommand"](params);
11649
11705
  return [4
11650
11706
  /*yield*/
11651
11707
  , this.lexRuntimeServiceClient.send(postTextCommand)];
11652
11708
 
11653
- case 3:
11654
- data = _a.sent();
11709
+ case 6:
11710
+ data = _c.sent();
11655
11711
  this.reportBotStatus(data, botname);
11656
11712
  return [2
11657
11713
  /*return*/
11658
11714
  , data];
11659
11715
 
11660
- case 4:
11661
- err_1 = _a.sent();
11716
+ case 7:
11717
+ err_1 = _c.sent();
11662
11718
  return [2
11663
11719
  /*return*/
11664
11720
  , Promise.reject(err_1)];
11665
11721
 
11666
- case 5:
11722
+ case 8:
11667
11723
  return [3
11668
11724
  /*break*/
11669
- , 11];
11725
+ , 19];
11670
11726
 
11671
- case 6:
11727
+ case 9:
11672
11728
  content = message.content, messageType = message.options.messageType;
11729
+ if (!(messageType === 'voice')) return [3
11730
+ /*break*/
11731
+ , 11];
11732
+ if (!(content instanceof Blob || content instanceof ReadableStream)) return [2
11733
+ /*return*/
11734
+ , Promise.reject('invalid content type')];
11735
+ _a = {
11736
+ botAlias: this._config[botname].alias,
11737
+ botName: botname,
11738
+ contentType: 'audio/x-l16; sample-rate=16000; channel-count=1'
11739
+ };
11740
+ return [4
11741
+ /*yield*/
11742
+ , Object(_AWSLexProviderHelper_convert__WEBPACK_IMPORTED_MODULE_3__["convert"])(content)];
11673
11743
 
11674
- if (messageType === 'voice') {
11675
- params = {
11676
- botAlias: this._config[botname].alias,
11677
- botName: botname,
11678
- contentType: 'audio/x-l16; sample-rate=16000',
11679
- inputStream: content,
11680
- userId: credentials.identityId,
11681
- accept: 'audio/mpeg'
11682
- };
11683
- } else {
11684
- params = {
11685
- botAlias: this._config[botname].alias,
11686
- botName: botname,
11687
- contentType: 'text/plain; charset=utf-8',
11688
- inputStream: content,
11689
- userId: credentials.identityId,
11690
- accept: 'audio/mpeg'
11691
- };
11692
- }
11744
+ case 10:
11745
+ params = (_a.inputStream = _c.sent(), _a.userId = credentials.identityId, _a.accept = 'audio/mpeg', _a);
11746
+ return [3
11747
+ /*break*/
11748
+ , 12];
11749
+
11750
+ case 11:
11751
+ if (typeof content !== 'string') return [2
11752
+ /*return*/
11753
+ , Promise.reject('invalid content type')];
11754
+ params = {
11755
+ botAlias: this._config[botname].alias,
11756
+ botName: botname,
11757
+ contentType: 'text/plain; charset=utf-8',
11758
+ inputStream: content,
11759
+ userId: credentials.identityId,
11760
+ accept: 'audio/mpeg'
11761
+ };
11762
+ _c.label = 12;
11693
11763
 
11764
+ case 12:
11694
11765
  logger.debug('postContent to lex', message);
11695
- _a.label = 7;
11766
+ _c.label = 13;
11696
11767
 
11697
- case 7:
11698
- _a.trys.push([7, 10,, 11]);
11768
+ case 13:
11769
+ _c.trys.push([13, 18,, 19]);
11699
11770
 
11700
11771
  postContentCommand = new _aws_sdk_client_lex_runtime_service__WEBPACK_IMPORTED_MODULE_1__["PostContentCommand"](params);
11701
11772
  return [4
11702
11773
  /*yield*/
11703
11774
  , this.lexRuntimeServiceClient.send(postContentCommand)];
11704
11775
 
11705
- case 8:
11706
- data = _a.sent();
11776
+ case 14:
11777
+ data = _c.sent();
11778
+ if (!data.audioStream) return [3
11779
+ /*break*/
11780
+ , 16];
11707
11781
  return [4
11708
11782
  /*yield*/
11709
11783
  , Object(_AWSLexProviderHelper_convert__WEBPACK_IMPORTED_MODULE_3__["convert"])(data.audioStream)];
11710
11784
 
11711
- case 9:
11712
- audioArray = _a.sent();
11785
+ case 15:
11786
+ _b = _c.sent();
11787
+ return [3
11788
+ /*break*/
11789
+ , 17];
11790
+
11791
+ case 16:
11792
+ _b = undefined;
11793
+ _c.label = 17;
11794
+
11795
+ case 17:
11796
+ audioArray = _b;
11713
11797
  this.reportBotStatus(data, botname);
11714
11798
  return [2
11715
11799
  /*return*/
@@ -11717,13 +11801,13 @@ function (_super) {
11717
11801
  audioStream: audioArray
11718
11802
  })];
11719
11803
 
11720
- case 10:
11721
- err_2 = _a.sent();
11804
+ case 18:
11805
+ err_2 = _c.sent();
11722
11806
  return [2
11723
11807
  /*return*/
11724
11808
  , Promise.reject(err_2)];
11725
11809
 
11726
- case 11:
11810
+ case 19:
11727
11811
  return [2
11728
11812
  /*return*/
11729
11813
  ];
@@ -11733,8 +11817,9 @@ function (_super) {
11733
11817
  };
11734
11818
 
11735
11819
  AWSLexProvider.prototype.onComplete = function (botname, callback) {
11820
+ // does bot exist
11736
11821
  if (!this._config[botname]) {
11737
- throw new ErrorEvent('Bot ' + botname + ' does not exist');
11822
+ throw new Error('Bot ' + botname + ' does not exist');
11738
11823
  }
11739
11824
 
11740
11825
  this._botsCompleteCallback[botname] = callback;
@@ -11887,7 +11972,7 @@ __webpack_require__.r(__webpack_exports__);
11887
11972
  /*!**************************!*\
11888
11973
  !*** ./lib-esm/index.js ***!
11889
11974
  \**************************/
11890
- /*! exports provided: default, AWSLexProvider, Interactions */
11975
+ /*! exports provided: default, AbstractInteractionsProvider, AWSLexProvider, Interactions */
11891
11976
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
11892
11977
 
11893
11978
  "use strict";
@@ -11895,8 +11980,11 @@ __webpack_require__.r(__webpack_exports__);
11895
11980
  /* harmony import */ var _Interactions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Interactions */ "./lib-esm/Interactions.js");
11896
11981
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Interactions", function() { return _Interactions__WEBPACK_IMPORTED_MODULE_0__["Interactions"]; });
11897
11982
 
11898
- /* harmony import */ var _Providers_AWSLexProvider__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Providers/AWSLexProvider */ "./lib-esm/Providers/AWSLexProvider.js");
11899
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AWSLexProvider", function() { return _Providers_AWSLexProvider__WEBPACK_IMPORTED_MODULE_1__["AWSLexProvider"]; });
11983
+ /* harmony import */ var _Providers_InteractionsProvider__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Providers/InteractionsProvider */ "./lib-esm/Providers/InteractionsProvider.js");
11984
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AbstractInteractionsProvider", function() { return _Providers_InteractionsProvider__WEBPACK_IMPORTED_MODULE_1__["AbstractInteractionsProvider"]; });
11985
+
11986
+ /* harmony import */ var _Providers_AWSLexProvider__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Providers/AWSLexProvider */ "./lib-esm/Providers/AWSLexProvider.js");
11987
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AWSLexProvider", function() { return _Providers_AWSLexProvider__WEBPACK_IMPORTED_MODULE_2__["AWSLexProvider"]; });
11900
11988
 
11901
11989
  /*
11902
11990
  * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
@@ -11919,6 +12007,7 @@ __webpack_require__.r(__webpack_exports__);
11919
12007
 
11920
12008
 
11921
12009
 
12010
+
11922
12011
  /***/ }),
11923
12012
 
11924
12013
  /***/ "@aws-amplify/core":