@aws-amplify/interactions 4.0.48 → 4.0.49-clean-npm-artifacts.25
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/CHANGELOG.md +78 -0
- package/lib/.tsbuildinfo +3 -0
- package/lib/Interactions.d.ts +2 -2
- package/lib/Interactions.js +41 -68
- package/lib/Interactions.js.map +1 -1
- package/lib/Providers/AWSLexProvider.d.ts +16 -3
- package/lib/Providers/AWSLexProvider.js +106 -119
- package/lib/Providers/AWSLexProvider.js.map +1 -1
- package/lib/Providers/AWSLexProviderHelper/commonUtils.d.ts +1 -0
- package/lib/Providers/AWSLexProviderHelper/commonUtils.js +39 -0
- package/lib/Providers/AWSLexProviderHelper/commonUtils.js.map +1 -0
- package/lib/Providers/AWSLexProviderHelper/utils.d.ts +3 -0
- package/lib/Providers/AWSLexProviderHelper/utils.js +48 -0
- package/lib/Providers/AWSLexProviderHelper/utils.js.map +1 -0
- package/lib/Providers/AWSLexProviderHelper/utils.native.d.ts +3 -0
- package/lib/Providers/AWSLexProviderHelper/utils.native.js +65 -0
- package/lib/Providers/AWSLexProviderHelper/utils.native.js.map +1 -0
- package/lib/Providers/AWSLexV2Provider.d.ts +58 -0
- package/lib/Providers/AWSLexV2Provider.js +292 -0
- package/lib/Providers/AWSLexV2Provider.js.map +1 -0
- package/lib/Providers/InteractionsProvider.js +3 -13
- package/lib/Providers/InteractionsProvider.js.map +1 -1
- package/lib/Providers/index.d.ts +1 -0
- package/lib/Providers/index.js +4 -5
- package/lib/Providers/index.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/types/Provider.d.ts +2 -1
- package/lib/types/Providers/AWSLexProvider.d.ts +10 -0
- package/lib/types/Providers/AWSLexProvider.js +3 -0
- package/lib/types/Providers/AWSLexProvider.js.map +1 -0
- package/lib/types/Providers/AWSLexV2Provider.d.ts +12 -0
- package/lib/types/Providers/AWSLexV2Provider.js +3 -0
- package/lib/types/Providers/AWSLexV2Provider.js.map +1 -0
- package/lib/types/index.d.ts +2 -0
- package/lib-esm/.tsbuildinfo +3 -0
- package/lib-esm/Interactions.d.ts +2 -2
- package/lib-esm/Interactions.js +38 -65
- package/lib-esm/Interactions.js.map +1 -1
- package/lib-esm/Providers/AWSLexProvider.d.ts +16 -3
- package/lib-esm/Providers/AWSLexProvider.js +102 -115
- package/lib-esm/Providers/AWSLexProvider.js.map +1 -1
- package/lib-esm/Providers/AWSLexProviderHelper/commonUtils.d.ts +1 -0
- package/lib-esm/Providers/AWSLexProviderHelper/commonUtils.js +37 -0
- package/lib-esm/Providers/AWSLexProviderHelper/commonUtils.js.map +1 -0
- package/lib-esm/Providers/AWSLexProviderHelper/utils.d.ts +3 -0
- package/lib-esm/Providers/AWSLexProviderHelper/utils.js +46 -0
- package/lib-esm/Providers/AWSLexProviderHelper/utils.js.map +1 -0
- package/lib-esm/Providers/AWSLexProviderHelper/utils.native.d.ts +3 -0
- package/lib-esm/Providers/AWSLexProviderHelper/utils.native.js +63 -0
- package/lib-esm/Providers/AWSLexProviderHelper/utils.native.js.map +1 -0
- package/lib-esm/Providers/AWSLexV2Provider.d.ts +58 -0
- package/lib-esm/Providers/AWSLexV2Provider.js +290 -0
- package/lib-esm/Providers/AWSLexV2Provider.js.map +1 -0
- package/lib-esm/Providers/InteractionsProvider.js +1 -11
- package/lib-esm/Providers/InteractionsProvider.js.map +1 -1
- package/lib-esm/Providers/index.d.ts +1 -0
- package/lib-esm/Providers/index.js +1 -0
- package/lib-esm/Providers/index.js.map +1 -1
- package/lib-esm/index.d.ts +2 -0
- package/lib-esm/index.js +2 -0
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/types/Provider.d.ts +2 -1
- package/lib-esm/types/Providers/AWSLexProvider.d.ts +10 -0
- package/lib-esm/types/Providers/AWSLexProvider.js +1 -0
- package/lib-esm/types/Providers/AWSLexProvider.js.map +1 -0
- package/lib-esm/types/Providers/AWSLexV2Provider.d.ts +12 -0
- package/lib-esm/types/Providers/AWSLexV2Provider.js +1 -0
- package/lib-esm/types/Providers/AWSLexV2Provider.js.map +1 -0
- package/lib-esm/types/index.d.ts +2 -0
- package/package.json +14 -4
- package/src/Interactions.ts +43 -21
- package/src/Providers/AWSLexProvider.ts +70 -23
- package/src/Providers/AWSLexProviderHelper/commonUtils.ts +27 -0
- package/src/Providers/AWSLexProviderHelper/utils.native.ts +56 -0
- package/src/Providers/AWSLexProviderHelper/utils.ts +39 -0
- package/src/Providers/AWSLexV2Provider.ts +343 -0
- package/src/Providers/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/types/Provider.ts +1 -1
- package/src/types/Providers/AWSLexProvider.ts +23 -0
- package/src/types/Providers/AWSLexV2Provider.ts +25 -0
- package/src/types/index.ts +2 -0
- package/build.js +0 -5
- package/dist/aws-amplify-interactions.js +0 -11937
- package/dist/aws-amplify-interactions.js.map +0 -1
- package/dist/aws-amplify-interactions.min.js +0 -26
- package/dist/aws-amplify-interactions.min.js.map +0 -1
- package/index.js +0 -7
- package/lib/Providers/AWSLexProviderHelper/convert.d.ts +0 -3
- package/lib/Providers/AWSLexProviderHelper/convert.js +0 -13
- package/lib/Providers/AWSLexProviderHelper/convert.js.map +0 -1
- package/lib/Providers/AWSLexProviderHelper/convert.native.d.ts +0 -1
- package/lib/Providers/AWSLexProviderHelper/convert.native.js +0 -56
- package/lib/Providers/AWSLexProviderHelper/convert.native.js.map +0 -1
- package/lib-esm/Providers/AWSLexProviderHelper/convert.d.ts +0 -3
- package/lib-esm/Providers/AWSLexProviderHelper/convert.js +0 -11
- package/lib-esm/Providers/AWSLexProviderHelper/convert.js.map +0 -1
- package/lib-esm/Providers/AWSLexProviderHelper/convert.native.d.ts +0 -1
- package/lib-esm/Providers/AWSLexProviderHelper/convert.native.js +0 -54
- package/lib-esm/Providers/AWSLexProviderHelper/convert.native.js.map +0 -1
- package/src/Providers/AWSLexProviderHelper/convert.native.ts +0 -13
- package/src/Providers/AWSLexProviderHelper/convert.ts +0 -12
- package/webpack.config.dev.js +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,84 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.1.3](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/interactions@4.1.1...@aws-amplify/interactions@4.1.3) (2022-09-30)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **@aws-amplify/interactions:** Upgrade client lex runtime v2 ([#10328](https://github.com/aws-amplify/amplify-js/issues/10328)) ([41ab57a](https://github.com/aws-amplify/amplify-js/commit/41ab57a854676813c3f9d89d647a8ac8f7b2c65f))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [4.1.2](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/interactions@4.1.1...@aws-amplify/interactions@4.1.2) (2022-09-20)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **@aws-amplify/interactions:** Upgrade client lex runtime v2 ([#10328](https://github.com/aws-amplify/amplify-js/issues/10328)) ([171b0c0](https://github.com/aws-amplify/amplify-js/commit/171b0c0d3523a7082d490e20c503027e306d953f))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## [4.1.1](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/interactions@4.1.0...@aws-amplify/interactions@4.1.1) (2022-09-08)
|
|
29
|
+
|
|
30
|
+
**Note:** Version bump only for package @aws-amplify/interactions
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# [4.1.0](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/interactions@4.0.51...@aws-amplify/interactions@4.1.0) (2022-09-01)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
* **@aws-amplify/interactions:** add audio type Uint8Array to lexV1 ([#10273](https://github.com/aws-amplify/amplify-js/issues/10273)) ([840086d](https://github.com/aws-amplify/amplify-js/commit/840086d6b58276c06128141cd04434e23d26e3a5))
|
|
42
|
+
* **@aws-amplify/interactions:** use pako instead of fflate in RN ([#10278](https://github.com/aws-amplify/amplify-js/issues/10278)) ([0c804e4](https://github.com/aws-amplify/amplify-js/commit/0c804e402da30ed3bfdd25f5c16fd2e0dfd5a07b))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Features
|
|
46
|
+
|
|
47
|
+
* **@aws-amplify/interactions:** Add LexV2 support to interactions ([#10217](https://github.com/aws-amplify/amplify-js/issues/10217)) ([91fdcd9](https://github.com/aws-amplify/amplify-js/commit/91fdcd919ee59f4e92b4abbbc18b33e3e38ed17e)), closes [#10167](https://github.com/aws-amplify/amplify-js/issues/10167)
|
|
48
|
+
* **@aws-amplify/interactions:** call onComplete callback with entire response ([#10248](https://github.com/aws-amplify/amplify-js/issues/10248)) ([7f2534d](https://github.com/aws-amplify/amplify-js/commit/7f2534d5dc2c936eadc12b5d49c86a3704051f4a))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## [4.0.51](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/interactions@4.0.50...@aws-amplify/interactions@4.0.51) (2022-08-23)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
### Bug Fixes
|
|
58
|
+
|
|
59
|
+
* **interactions:** fix addPluggable API ([#10250](https://github.com/aws-amplify/amplify-js/issues/10250)) ([01aad60](https://github.com/aws-amplify/amplify-js/commit/01aad60ff14c3db47761db819dd47def75bfcb9d))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## [4.0.50](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/interactions@4.0.49...@aws-amplify/interactions@4.0.50) (2022-08-18)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
### Bug Fixes
|
|
69
|
+
|
|
70
|
+
* **interactions:** fix configure default provider ([#10215](https://github.com/aws-amplify/amplify-js/issues/10215)) ([d4c3955](https://github.com/aws-amplify/amplify-js/commit/d4c395520bc66f24325babbe53e6ab7ebdea4d3b))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## [4.0.49](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/interactions@4.0.48...@aws-amplify/interactions@4.0.49) (2022-08-16)
|
|
77
|
+
|
|
78
|
+
**Note:** Version bump only for package @aws-amplify/interactions
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
6
84
|
## [4.0.48](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/interactions@4.0.47...@aws-amplify/interactions@4.0.48) (2022-08-01)
|
|
7
85
|
|
|
8
86
|
**Note:** Version bump only for package @aws-amplify/interactions
|
package/lib/.tsbuildinfo
ADDED
package/lib/Interactions.d.ts
CHANGED
|
@@ -7,12 +7,12 @@ export declare class InteractionsClass {
|
|
|
7
7
|
*
|
|
8
8
|
* @param {InteractionsOptions} options - Configuration object for Interactions
|
|
9
9
|
*/
|
|
10
|
-
constructor(options
|
|
10
|
+
constructor(options?: InteractionsOptions);
|
|
11
11
|
getModuleName(): string;
|
|
12
12
|
/**
|
|
13
13
|
*
|
|
14
14
|
* @param {InteractionsOptions} options - Configuration object for Interactions
|
|
15
|
-
* @return {
|
|
15
|
+
* @return {InteractionsOptions} - The current configuration
|
|
16
16
|
*/
|
|
17
17
|
configure(options: InteractionsOptions): InteractionsOptions;
|
|
18
18
|
addPluggable(pluggable: InteractionsProvider): void;
|
package/lib/Interactions.js
CHANGED
|
@@ -1,52 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
50
4
|
var core_1 = require("@aws-amplify/core");
|
|
51
5
|
var Providers_1 = require("./Providers");
|
|
52
6
|
var logger = new core_1.ConsoleLogger('Interactions');
|
|
@@ -57,6 +11,7 @@ var InteractionsClass = /** @class */ (function () {
|
|
|
57
11
|
* @param {InteractionsOptions} options - Configuration object for Interactions
|
|
58
12
|
*/
|
|
59
13
|
function InteractionsClass(options) {
|
|
14
|
+
if (options === void 0) { options = {}; }
|
|
60
15
|
this._options = options;
|
|
61
16
|
logger.debug('Interactions Options', this._options);
|
|
62
17
|
this._pluggables = {};
|
|
@@ -67,13 +22,13 @@ var InteractionsClass = /** @class */ (function () {
|
|
|
67
22
|
/**
|
|
68
23
|
*
|
|
69
24
|
* @param {InteractionsOptions} options - Configuration object for Interactions
|
|
70
|
-
* @return {
|
|
25
|
+
* @return {InteractionsOptions} - The current configuration
|
|
71
26
|
*/
|
|
72
27
|
InteractionsClass.prototype.configure = function (options) {
|
|
73
28
|
var _this = this;
|
|
74
29
|
var opt = options ? options.Interactions || options : {};
|
|
75
30
|
logger.debug('configure Interactions', { opt: opt });
|
|
76
|
-
this._options = __assign(__assign({ bots: {} }, opt), opt.Interactions);
|
|
31
|
+
this._options = tslib_1.__assign(tslib_1.__assign({ bots: {} }, opt), opt.Interactions);
|
|
77
32
|
var aws_bots_config = this._options.aws_bots_config;
|
|
78
33
|
var bots_config = this._options.bots;
|
|
79
34
|
if (!Object.keys(bots_config).length && aws_bots_config) {
|
|
@@ -84,45 +39,63 @@ var InteractionsClass = /** @class */ (function () {
|
|
|
84
39
|
});
|
|
85
40
|
}
|
|
86
41
|
}
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
42
|
+
// configure bots to their specific providers
|
|
43
|
+
Object.keys(bots_config).forEach(function (botKey) {
|
|
44
|
+
var _a;
|
|
45
|
+
var bot = bots_config[botKey];
|
|
46
|
+
var providerName = bot.providerName || 'AWSLexProvider';
|
|
47
|
+
// add default provider if required
|
|
48
|
+
if (!_this._pluggables.AWSLexProvider &&
|
|
49
|
+
providerName === 'AWSLexProvider') {
|
|
50
|
+
_this._pluggables.AWSLexProvider = new Providers_1.AWSLexProvider();
|
|
51
|
+
}
|
|
52
|
+
// configure bot with it's respective provider
|
|
53
|
+
if (_this._pluggables[providerName]) {
|
|
54
|
+
_this._pluggables[providerName].configure((_a = {}, _a[bot.name] = bot, _a));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
logger.debug("bot " + bot.name + " was not configured as " + providerName + " provider was not found");
|
|
58
|
+
}
|
|
97
59
|
});
|
|
98
60
|
return this._options;
|
|
99
61
|
};
|
|
100
62
|
InteractionsClass.prototype.addPluggable = function (pluggable) {
|
|
63
|
+
var _this = this;
|
|
101
64
|
if (pluggable && pluggable.getCategory() === 'Interactions') {
|
|
102
65
|
if (!this._pluggables[pluggable.getProviderName()]) {
|
|
103
|
-
|
|
66
|
+
// configure bots for the new plugin
|
|
67
|
+
Object.keys(this._options.bots)
|
|
68
|
+
.filter(function (botKey) {
|
|
69
|
+
return _this._options.bots[botKey].providerName ===
|
|
70
|
+
pluggable.getProviderName();
|
|
71
|
+
})
|
|
72
|
+
.forEach(function (botKey) {
|
|
73
|
+
var _a;
|
|
74
|
+
var bot = _this._options.bots[botKey];
|
|
75
|
+
pluggable.configure((_a = {}, _a[bot.name] = bot, _a));
|
|
76
|
+
});
|
|
104
77
|
this._pluggables[pluggable.getProviderName()] = pluggable;
|
|
105
78
|
return;
|
|
106
79
|
}
|
|
107
80
|
else {
|
|
108
|
-
throw new Error('
|
|
81
|
+
throw new Error('Pluggable ' + pluggable.getProviderName() + ' already plugged');
|
|
109
82
|
}
|
|
110
83
|
}
|
|
111
84
|
};
|
|
112
85
|
InteractionsClass.prototype.send = function (botname, message) {
|
|
113
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
114
87
|
var botProvider;
|
|
115
|
-
return __generator(this, function (_a) {
|
|
88
|
+
return tslib_1.__generator(this, function (_a) {
|
|
116
89
|
switch (_a.label) {
|
|
117
90
|
case 0:
|
|
118
91
|
if (!this._options.bots || !this._options.bots[botname]) {
|
|
119
|
-
|
|
92
|
+
return [2 /*return*/, Promise.reject('Bot ' + botname + ' does not exist')];
|
|
120
93
|
}
|
|
121
94
|
botProvider = this._options.bots[botname].providerName || 'AWSLexProvider';
|
|
122
95
|
if (!this._pluggables[botProvider]) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
96
|
+
return [2 /*return*/, Promise.reject('Bot ' +
|
|
97
|
+
botProvider +
|
|
98
|
+
' does not have valid pluggin did you try addPluggable first?')];
|
|
126
99
|
}
|
|
127
100
|
return [4 /*yield*/, this._pluggables[botProvider].sendMessage(botname, message)];
|
|
128
101
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -145,6 +118,6 @@ var InteractionsClass = /** @class */ (function () {
|
|
|
145
118
|
return InteractionsClass;
|
|
146
119
|
}());
|
|
147
120
|
exports.InteractionsClass = InteractionsClass;
|
|
148
|
-
exports.Interactions = new InteractionsClass(
|
|
121
|
+
exports.Interactions = new InteractionsClass();
|
|
149
122
|
core_1.Amplify.register(exports.Interactions);
|
|
150
123
|
//# sourceMappingURL=Interactions.js.map
|
package/lib/Interactions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interactions.js","sourceRoot":"","sources":["../src/Interactions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Interactions.js","sourceRoot":"","sources":["../src/Interactions.ts"],"names":[],"mappings":";;;AAmBA,0CAAqE;AACrE,yCAA6C;AAC7C,IAAM,MAAM,GAAG,IAAI,oBAAM,CAAC,cAAc,CAAC,CAAC;AAE1C;IAKC;;;;OAIG;IACH,2BAAY,OAAiC;QAAjC,wBAAA,EAAA,YAAiC;QAC5C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpD,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACvB,CAAC;IAEM,yCAAa,GAApB;QACC,OAAO,cAAc,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,qCAAS,GAAhB,UAAiB,OAA4B;QAA7C,iBAyCC;QAxCA,IAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3D,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAA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Message } from '../types';
|
|
2
|
+
import { InteractionsOptions, AWSLexProviderOptions, InteractionsResponse, InteractionsMessage } from '../types';
|
|
3
|
+
import { PostTextCommandOutput, PostContentCommandOutput } from '@aws-sdk/client-lex-runtime-service';
|
|
4
|
+
interface PostContentCommandOutputFormatted extends Omit<PostContentCommandOutput, 'audioStream'> {
|
|
5
|
+
audioStream?: Uint8Array;
|
|
6
|
+
}
|
|
7
|
+
declare type AWSLexProviderSendResponse = PostTextCommandOutput | PostContentCommandOutputFormatted;
|
|
3
8
|
export declare class AWSLexProvider extends AbstractInteractionsProvider {
|
|
4
9
|
private lexRuntimeServiceClient;
|
|
5
10
|
private _botsCompleteCallback;
|
|
6
11
|
constructor(options?: InteractionsOptions);
|
|
7
12
|
getProviderName(): string;
|
|
8
|
-
|
|
13
|
+
configure(config?: AWSLexProviderOptions): AWSLexProviderOptions;
|
|
14
|
+
/**
|
|
15
|
+
* @private
|
|
16
|
+
* @deprecated
|
|
17
|
+
* This is used internally by 'sendMessage' to call onComplete callback
|
|
18
|
+
* for a bot if configured
|
|
19
|
+
*/
|
|
20
|
+
reportBotStatus(data: AWSLexProviderSendResponse, botname: string): void;
|
|
9
21
|
sendMessage(botname: string, message: string | InteractionsMessage): Promise<InteractionsResponse>;
|
|
10
|
-
onComplete(botname: string, callback: any): void;
|
|
22
|
+
onComplete(botname: string, callback: (err: any, confirmation: any) => void): void;
|
|
11
23
|
}
|
|
24
|
+
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
2
4
|
/*
|
|
3
5
|
* Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
6
|
*
|
|
@@ -11,74 +13,13 @@
|
|
|
11
13
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
12
14
|
* and limitations under the License.
|
|
13
15
|
*/
|
|
14
|
-
var __extends = (this && this.__extends) || (function () {
|
|
15
|
-
var extendStatics = function (d, b) {
|
|
16
|
-
extendStatics = Object.setPrototypeOf ||
|
|
17
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
18
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
19
|
-
return extendStatics(d, b);
|
|
20
|
-
};
|
|
21
|
-
return function (d, b) {
|
|
22
|
-
extendStatics(d, b);
|
|
23
|
-
function __() { this.constructor = d; }
|
|
24
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
25
|
-
};
|
|
26
|
-
})();
|
|
27
|
-
var __assign = (this && this.__assign) || function () {
|
|
28
|
-
__assign = Object.assign || function(t) {
|
|
29
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
30
|
-
s = arguments[i];
|
|
31
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
32
|
-
t[p] = s[p];
|
|
33
|
-
}
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
|
-
return __assign.apply(this, arguments);
|
|
37
|
-
};
|
|
38
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
39
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
40
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
41
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
42
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
43
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
44
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
48
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
49
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
50
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
51
|
-
function step(op) {
|
|
52
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
53
|
-
while (_) try {
|
|
54
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
55
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
56
|
-
switch (op[0]) {
|
|
57
|
-
case 0: case 1: t = op; break;
|
|
58
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
59
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
60
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
61
|
-
default:
|
|
62
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
63
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
64
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
65
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
66
|
-
if (t[2]) _.ops.pop();
|
|
67
|
-
_.trys.pop(); continue;
|
|
68
|
-
}
|
|
69
|
-
op = body.call(thisArg, _);
|
|
70
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
71
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
16
|
var InteractionsProvider_1 = require("./InteractionsProvider");
|
|
76
17
|
var client_lex_runtime_service_1 = require("@aws-sdk/client-lex-runtime-service");
|
|
77
18
|
var core_1 = require("@aws-amplify/core");
|
|
78
|
-
var
|
|
19
|
+
var utils_1 = require("./AWSLexProviderHelper/utils");
|
|
79
20
|
var logger = new core_1.ConsoleLogger('AWSLexProvider');
|
|
80
21
|
var AWSLexProvider = /** @class */ (function (_super) {
|
|
81
|
-
__extends(AWSLexProvider, _super);
|
|
22
|
+
tslib_1.__extends(AWSLexProvider, _super);
|
|
82
23
|
function AWSLexProvider(options) {
|
|
83
24
|
if (options === void 0) { options = {}; }
|
|
84
25
|
var _this = _super.call(this, options) || this;
|
|
@@ -88,6 +29,24 @@ var AWSLexProvider = /** @class */ (function (_super) {
|
|
|
88
29
|
AWSLexProvider.prototype.getProviderName = function () {
|
|
89
30
|
return 'AWSLexProvider';
|
|
90
31
|
};
|
|
32
|
+
AWSLexProvider.prototype.configure = function (config) {
|
|
33
|
+
if (config === void 0) { config = {}; }
|
|
34
|
+
var propertiesToTest = ['name', 'alias', 'region'];
|
|
35
|
+
Object.keys(config).forEach(function (botKey) {
|
|
36
|
+
var botConfig = config[botKey];
|
|
37
|
+
// is bot config correct
|
|
38
|
+
if (!propertiesToTest.every(function (x) { return x in botConfig; })) {
|
|
39
|
+
throw new Error('invalid bot configuration');
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return _super.prototype.configure.call(this, config);
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @private
|
|
46
|
+
* @deprecated
|
|
47
|
+
* This is used internally by 'sendMessage' to call onComplete callback
|
|
48
|
+
* for a bot if configured
|
|
49
|
+
*/
|
|
91
50
|
AWSLexProvider.prototype.reportBotStatus = function (data, botname) {
|
|
92
51
|
var _this = this;
|
|
93
52
|
// Check if state is fulfilled to resolve onFullfilment promise
|
|
@@ -95,13 +54,11 @@ var AWSLexProvider = /** @class */ (function (_super) {
|
|
|
95
54
|
if (data.dialogState === 'ReadyForFulfillment' ||
|
|
96
55
|
data.dialogState === 'Fulfilled') {
|
|
97
56
|
if (typeof this._botsCompleteCallback[botname] === 'function') {
|
|
98
|
-
setTimeout(function () {
|
|
99
|
-
return _this._botsCompleteCallback[botname](null, { slots: data.slots });
|
|
100
|
-
}, 0);
|
|
57
|
+
setTimeout(function () { return _this._botsCompleteCallback[botname](null, data); }, 0);
|
|
101
58
|
}
|
|
102
59
|
if (this._config &&
|
|
103
60
|
typeof this._config[botname].onComplete === 'function') {
|
|
104
|
-
setTimeout(function () { return _this._config[botname].onComplete(null,
|
|
61
|
+
setTimeout(function () { return _this._config[botname].onComplete(null, data); }, 0);
|
|
105
62
|
}
|
|
106
63
|
}
|
|
107
64
|
if (data.dialogState === 'Failed') {
|
|
@@ -115,26 +72,32 @@ var AWSLexProvider = /** @class */ (function (_super) {
|
|
|
115
72
|
}
|
|
116
73
|
};
|
|
117
74
|
AWSLexProvider.prototype.sendMessage = function (botname, message) {
|
|
118
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
-
var credentials, params, postTextCommand, data, err_1, content, messageType, postContentCommand, data, audioArray, err_2;
|
|
120
|
-
return __generator(this, function (
|
|
121
|
-
switch (
|
|
75
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
76
|
+
var credentials, error_1, params, postTextCommand, data, err_1, content, messageType, inputStream, _a, postContentCommand, data, audioArray, _b, response, err_2;
|
|
77
|
+
return tslib_1.__generator(this, function (_c) {
|
|
78
|
+
switch (_c.label) {
|
|
122
79
|
case 0:
|
|
80
|
+
// check if bot exists
|
|
123
81
|
if (!this._config[botname]) {
|
|
124
82
|
return [2 /*return*/, Promise.reject('Bot ' + botname + ' does not exist')];
|
|
125
83
|
}
|
|
126
|
-
|
|
84
|
+
_c.label = 1;
|
|
127
85
|
case 1:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
86
|
+
_c.trys.push([1, 3, , 4]);
|
|
87
|
+
return [4 /*yield*/, core_1.Credentials.get()];
|
|
88
|
+
case 2:
|
|
89
|
+
credentials = _c.sent();
|
|
90
|
+
return [3 /*break*/, 4];
|
|
91
|
+
case 3:
|
|
92
|
+
error_1 = _c.sent();
|
|
93
|
+
return [2 /*return*/, Promise.reject('No credentials')];
|
|
94
|
+
case 4:
|
|
132
95
|
this.lexRuntimeServiceClient = new client_lex_runtime_service_1.LexRuntimeServiceClient({
|
|
133
96
|
region: this._config[botname].region,
|
|
134
97
|
credentials: credentials,
|
|
135
98
|
customUserAgent: core_1.getAmplifyUserAgent(),
|
|
136
99
|
});
|
|
137
|
-
if (!(typeof message === 'string')) return [3 /*break*/,
|
|
100
|
+
if (!(typeof message === 'string')) return [3 /*break*/, 9];
|
|
138
101
|
params = {
|
|
139
102
|
botAlias: this._config[botname].alias,
|
|
140
103
|
botName: botname,
|
|
@@ -142,65 +105,89 @@ var AWSLexProvider = /** @class */ (function (_super) {
|
|
|
142
105
|
userId: credentials.identityId,
|
|
143
106
|
};
|
|
144
107
|
logger.debug('postText to lex', message);
|
|
145
|
-
|
|
146
|
-
case
|
|
147
|
-
|
|
108
|
+
_c.label = 5;
|
|
109
|
+
case 5:
|
|
110
|
+
_c.trys.push([5, 7, , 8]);
|
|
148
111
|
postTextCommand = new client_lex_runtime_service_1.PostTextCommand(params);
|
|
149
112
|
return [4 /*yield*/, this.lexRuntimeServiceClient.send(postTextCommand)];
|
|
150
|
-
case
|
|
151
|
-
data =
|
|
113
|
+
case 6:
|
|
114
|
+
data = _c.sent();
|
|
152
115
|
this.reportBotStatus(data, botname);
|
|
153
116
|
return [2 /*return*/, data];
|
|
154
|
-
case
|
|
155
|
-
err_1 =
|
|
117
|
+
case 7:
|
|
118
|
+
err_1 = _c.sent();
|
|
156
119
|
return [2 /*return*/, Promise.reject(err_1)];
|
|
157
|
-
case
|
|
158
|
-
case
|
|
120
|
+
case 8: return [3 /*break*/, 21];
|
|
121
|
+
case 9:
|
|
159
122
|
content = message.content, messageType = message.options.messageType;
|
|
160
|
-
if (messageType === 'voice')
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
botName: botname,
|
|
164
|
-
contentType: 'audio/x-l16; sample-rate=16000',
|
|
165
|
-
inputStream: content,
|
|
166
|
-
userId: credentials.identityId,
|
|
167
|
-
accept: 'audio/mpeg',
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
params = {
|
|
172
|
-
botAlias: this._config[botname].alias,
|
|
173
|
-
botName: botname,
|
|
174
|
-
contentType: 'text/plain; charset=utf-8',
|
|
175
|
-
inputStream: content,
|
|
176
|
-
userId: credentials.identityId,
|
|
177
|
-
accept: 'audio/mpeg',
|
|
178
|
-
};
|
|
123
|
+
if (!(messageType === 'voice')) return [3 /*break*/, 13];
|
|
124
|
+
if (typeof content !== 'object') {
|
|
125
|
+
return [2 /*return*/, Promise.reject('invalid content type')];
|
|
179
126
|
}
|
|
127
|
+
if (!(content instanceof Uint8Array)) return [3 /*break*/, 10];
|
|
128
|
+
_a = content;
|
|
129
|
+
return [3 /*break*/, 12];
|
|
130
|
+
case 10: return [4 /*yield*/, utils_1.convert(content)];
|
|
131
|
+
case 11:
|
|
132
|
+
_a = _c.sent();
|
|
133
|
+
_c.label = 12;
|
|
134
|
+
case 12:
|
|
135
|
+
inputStream = _a;
|
|
136
|
+
params = {
|
|
137
|
+
botAlias: this._config[botname].alias,
|
|
138
|
+
botName: botname,
|
|
139
|
+
contentType: 'audio/x-l16; sample-rate=16000; channel-count=1',
|
|
140
|
+
userId: credentials.identityId,
|
|
141
|
+
accept: 'audio/mpeg',
|
|
142
|
+
inputStream: inputStream,
|
|
143
|
+
};
|
|
144
|
+
return [3 /*break*/, 14];
|
|
145
|
+
case 13:
|
|
146
|
+
if (typeof content !== 'string')
|
|
147
|
+
return [2 /*return*/, Promise.reject('invalid content type')];
|
|
148
|
+
params = {
|
|
149
|
+
botAlias: this._config[botname].alias,
|
|
150
|
+
botName: botname,
|
|
151
|
+
contentType: 'text/plain; charset=utf-8',
|
|
152
|
+
inputStream: content,
|
|
153
|
+
userId: credentials.identityId,
|
|
154
|
+
accept: 'audio/mpeg',
|
|
155
|
+
};
|
|
156
|
+
_c.label = 14;
|
|
157
|
+
case 14:
|
|
180
158
|
logger.debug('postContent to lex', message);
|
|
181
|
-
|
|
182
|
-
case
|
|
183
|
-
|
|
159
|
+
_c.label = 15;
|
|
160
|
+
case 15:
|
|
161
|
+
_c.trys.push([15, 20, , 21]);
|
|
184
162
|
postContentCommand = new client_lex_runtime_service_1.PostContentCommand(params);
|
|
185
163
|
return [4 /*yield*/, this.lexRuntimeServiceClient.send(postContentCommand)];
|
|
186
|
-
case
|
|
187
|
-
data =
|
|
188
|
-
return [
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return [
|
|
193
|
-
case
|
|
194
|
-
|
|
164
|
+
case 16:
|
|
165
|
+
data = _c.sent();
|
|
166
|
+
if (!data.audioStream) return [3 /*break*/, 18];
|
|
167
|
+
return [4 /*yield*/, utils_1.convert(data.audioStream)];
|
|
168
|
+
case 17:
|
|
169
|
+
_b = _c.sent();
|
|
170
|
+
return [3 /*break*/, 19];
|
|
171
|
+
case 18:
|
|
172
|
+
_b = undefined;
|
|
173
|
+
_c.label = 19;
|
|
174
|
+
case 19:
|
|
175
|
+
audioArray = _b;
|
|
176
|
+
response = tslib_1.__assign(tslib_1.__assign({}, data), { audioStream: audioArray });
|
|
177
|
+
this.reportBotStatus(response, botname);
|
|
178
|
+
return [2 /*return*/, response];
|
|
179
|
+
case 20:
|
|
180
|
+
err_2 = _c.sent();
|
|
195
181
|
return [2 /*return*/, Promise.reject(err_2)];
|
|
196
|
-
case
|
|
182
|
+
case 21: return [2 /*return*/];
|
|
197
183
|
}
|
|
198
184
|
});
|
|
199
185
|
});
|
|
200
186
|
};
|
|
201
187
|
AWSLexProvider.prototype.onComplete = function (botname, callback) {
|
|
188
|
+
// does bot exist
|
|
202
189
|
if (!this._config[botname]) {
|
|
203
|
-
throw new
|
|
190
|
+
throw new Error('Bot ' + botname + ' does not exist');
|
|
204
191
|
}
|
|
205
192
|
this._botsCompleteCallback[botname] = callback;
|
|
206
193
|
};
|