@aws-amplify/interactions 5.2.12-unstable.7762f1a.0 → 6.0.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.
- package/README.md +3 -0
- package/lex-v1/package.json +7 -0
- package/lex-v2/package.json +7 -0
- package/lib/errors/InteractionsError.d.ts +4 -0
- package/lib/errors/InteractionsError.js +16 -0
- package/lib/errors/assertValidationError.d.ts +2 -0
- package/lib/errors/assertValidationError.js +18 -0
- package/lib/errors/index.d.ts +2 -0
- package/lib/errors/index.js +9 -0
- package/lib/errors/validation.d.ts +5 -0
- package/lib/errors/validation.js +14 -0
- package/lib/index.d.ts +2 -5
- package/lib/index.js +3 -9
- package/lib/lex-v1/AWSLexProvider.d.ts +20 -0
- package/lib/lex-v1/AWSLexProvider.js +119 -0
- package/lib/lex-v1/apis/index.d.ts +2 -0
- package/lib/lex-v1/apis/index.js +9 -0
- package/lib/lex-v1/apis/onComplete.d.ts +2 -0
- package/lib/lex-v1/apis/onComplete.js +15 -0
- package/lib/lex-v1/apis/send.d.ts +2 -0
- package/lib/lex-v1/apis/send.js +15 -0
- package/lib/lex-v1/index.d.ts +6 -0
- package/lib/lex-v1/index.js +13 -0
- package/lib/lex-v1/types/AWSLexProviderOption.d.ts +11 -0
- package/lib/{types/Response.js → lex-v1/types/AWSLexProviderOption.js} +0 -1
- package/lib/lex-v1/types/index.d.ts +3 -0
- package/lib/lex-v1/types/index.js +4 -0
- package/lib/lex-v1/types/inputs.d.ts +9 -0
- package/lib/lex-v1/types/inputs.js +4 -0
- package/lib/lex-v1/types/outputs.d.ts +5 -0
- package/lib/lex-v1/types/outputs.js +4 -0
- package/lib/lex-v1/utils/index.d.ts +1 -0
- package/lib/lex-v1/utils/index.js +7 -0
- package/lib/lex-v1/utils/resolveBotConfig.d.ts +2 -0
- package/lib/lex-v1/utils/resolveBotConfig.js +13 -0
- package/lib/lex-v2/AWSLexV2Provider.d.ts +52 -0
- package/lib/lex-v2/AWSLexV2Provider.js +166 -0
- package/lib/lex-v2/apis/index.d.ts +2 -0
- package/lib/lex-v2/apis/index.js +9 -0
- package/lib/lex-v2/apis/onComplete.d.ts +2 -0
- package/lib/lex-v2/apis/onComplete.js +15 -0
- package/lib/lex-v2/apis/send.d.ts +2 -0
- package/lib/lex-v2/apis/send.js +15 -0
- package/lib/lex-v2/index.d.ts +3 -0
- package/lib/lex-v2/index.js +10 -0
- package/lib/lex-v2/types/AWSLexV2ProviderOption.d.ts +13 -0
- package/lib/lex-v2/types/AWSLexV2ProviderOption.js +4 -0
- package/lib/lex-v2/types/index.d.ts +3 -0
- package/lib/lex-v2/types/index.js +4 -0
- package/lib/lex-v2/types/inputs.d.ts +9 -0
- package/lib/lex-v2/types/inputs.js +4 -0
- package/lib/lex-v2/types/outputs.d.ts +5 -0
- package/lib/lex-v2/types/outputs.js +4 -0
- package/lib/lex-v2/utils/index.d.ts +1 -0
- package/lib/lex-v2/utils/index.js +7 -0
- package/lib/lex-v2/utils/resolveBotConfig.d.ts +2 -0
- package/lib/lex-v2/utils/resolveBotConfig.js +13 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/Interactions.d.ts +7 -6
- package/lib/types/Interactions.js +2 -1
- package/lib/types/index.d.ts +2 -5
- package/lib/types/index.js +2 -1
- package/lib/types/inputs.d.ts +9 -0
- package/lib/types/inputs.js +4 -0
- package/lib/types/outputs.d.ts +2 -0
- package/lib/types/outputs.js +4 -0
- package/lib/utils/commonUtils.d.ts +1 -0
- package/lib/utils/commonUtils.js +19 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +11 -0
- package/lib/utils/utils.js +32 -0
- package/lib/utils/utils.native.js +45 -0
- package/lib-esm/errors/InteractionsError.d.ts +4 -0
- package/lib-esm/errors/InteractionsError.js +12 -0
- package/lib-esm/errors/assertValidationError.d.ts +2 -0
- package/lib-esm/errors/assertValidationError.js +14 -0
- package/lib-esm/errors/index.d.ts +2 -0
- package/lib-esm/errors/index.js +4 -0
- package/lib-esm/errors/validation.d.ts +5 -0
- package/lib-esm/errors/validation.js +11 -0
- package/lib-esm/index.d.ts +2 -5
- package/lib-esm/index.js +1 -5
- package/lib-esm/lex-v1/AWSLexProvider.d.ts +20 -0
- package/lib-esm/lex-v1/AWSLexProvider.js +116 -0
- package/lib-esm/lex-v1/apis/index.d.ts +2 -0
- package/lib-esm/lex-v1/apis/index.js +4 -0
- package/lib-esm/lex-v1/apis/onComplete.d.ts +2 -0
- package/lib-esm/lex-v1/apis/onComplete.js +11 -0
- package/lib-esm/lex-v1/apis/send.d.ts +2 -0
- package/lib-esm/lex-v1/apis/send.js +11 -0
- package/lib-esm/lex-v1/index.d.ts +6 -0
- package/lib-esm/lex-v1/index.js +10 -0
- package/lib-esm/lex-v1/types/AWSLexProviderOption.d.ts +11 -0
- package/lib-esm/{types/Response.js → lex-v1/types/AWSLexProviderOption.js} +1 -1
- package/lib-esm/lex-v1/types/index.d.ts +3 -0
- package/lib-esm/lex-v1/types/index.js +3 -0
- package/lib-esm/lex-v1/types/inputs.d.ts +9 -0
- package/lib-esm/lex-v1/types/inputs.js +3 -0
- package/lib-esm/lex-v1/types/outputs.d.ts +5 -0
- package/lib-esm/lex-v1/types/outputs.js +3 -0
- package/lib-esm/lex-v1/utils/index.d.ts +1 -0
- package/lib-esm/lex-v1/utils/index.js +3 -0
- package/lib-esm/lex-v1/utils/resolveBotConfig.d.ts +2 -0
- package/lib-esm/lex-v1/utils/resolveBotConfig.js +9 -0
- package/lib-esm/lex-v2/AWSLexV2Provider.d.ts +52 -0
- package/lib-esm/lex-v2/AWSLexV2Provider.js +163 -0
- package/lib-esm/lex-v2/apis/index.d.ts +2 -0
- package/lib-esm/lex-v2/apis/index.js +4 -0
- package/lib-esm/lex-v2/apis/onComplete.d.ts +2 -0
- package/lib-esm/lex-v2/apis/onComplete.js +11 -0
- package/lib-esm/lex-v2/apis/send.d.ts +2 -0
- package/lib-esm/lex-v2/apis/send.js +11 -0
- package/lib-esm/lex-v2/index.d.ts +3 -0
- package/lib-esm/lex-v2/index.js +7 -0
- package/lib-esm/lex-v2/types/AWSLexV2ProviderOption.d.ts +13 -0
- package/lib-esm/lex-v2/types/AWSLexV2ProviderOption.js +3 -0
- package/lib-esm/lex-v2/types/index.d.ts +3 -0
- package/lib-esm/lex-v2/types/index.js +3 -0
- package/lib-esm/lex-v2/types/inputs.d.ts +9 -0
- package/lib-esm/lex-v2/types/inputs.js +3 -0
- package/lib-esm/lex-v2/types/outputs.d.ts +5 -0
- package/lib-esm/lex-v2/types/outputs.js +3 -0
- package/lib-esm/lex-v2/utils/index.d.ts +1 -0
- package/lib-esm/lex-v2/utils/index.js +3 -0
- package/lib-esm/lex-v2/utils/resolveBotConfig.d.ts +2 -0
- package/lib-esm/lex-v2/utils/resolveBotConfig.js +9 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types/Interactions.d.ts +7 -6
- package/lib-esm/types/Interactions.js +3 -1
- package/lib-esm/types/index.d.ts +2 -5
- package/lib-esm/types/index.js +3 -1
- package/lib-esm/types/inputs.d.ts +9 -0
- package/lib-esm/types/inputs.js +3 -0
- package/lib-esm/types/outputs.d.ts +2 -0
- package/lib-esm/types/outputs.js +3 -0
- package/lib-esm/utils/commonUtils.d.ts +1 -0
- package/lib-esm/utils/commonUtils.js +15 -0
- package/lib-esm/utils/index.d.ts +2 -0
- package/lib-esm/utils/index.js +4 -0
- package/lib-esm/utils/utils.js +26 -0
- package/lib-esm/utils/utils.native.js +39 -0
- package/package.json +67 -28
- package/src/errors/InteractionsError.ts +18 -0
- package/src/errors/assertValidationError.ts +24 -0
- package/src/errors/index.ts +5 -0
- package/src/errors/validation.ts +15 -0
- package/src/index.ts +2 -5
- package/src/lex-v1/AWSLexProvider.ts +167 -0
- package/src/lex-v1/apis/index.ts +5 -0
- package/src/lex-v1/apis/onComplete.ts +21 -0
- package/src/lex-v1/apis/send.ts +21 -0
- package/src/lex-v1/index.ts +14 -0
- package/src/lex-v1/types/AWSLexProviderOption.ts +16 -0
- package/src/lex-v1/types/index.ts +6 -0
- package/src/lex-v1/types/inputs.ts +17 -0
- package/src/lex-v1/types/outputs.ts +9 -0
- package/src/{types/Response.ts → lex-v1/utils/index.ts} +1 -3
- package/src/lex-v1/utils/resolveBotConfig.ts +15 -0
- package/src/{Providers → lex-v2}/AWSLexV2Provider.ts +67 -137
- package/src/lex-v2/apis/index.ts +5 -0
- package/src/lex-v2/apis/onComplete.ts +21 -0
- package/src/lex-v2/apis/send.ts +21 -0
- package/src/lex-v2/index.ts +11 -0
- package/src/{types/Providers/AWSLexV2Provider.ts → lex-v2/types/AWSLexV2ProviderOption.ts} +7 -4
- package/src/lex-v2/types/index.ts +6 -0
- package/src/lex-v2/types/inputs.ts +17 -0
- package/src/lex-v2/types/outputs.ts +9 -0
- package/src/lex-v2/utils/index.ts +4 -0
- package/src/lex-v2/utils/resolveBotConfig.ts +15 -0
- package/src/types/Interactions.ts +9 -3
- package/src/types/index.ts +3 -5
- package/src/types/inputs.ts +17 -0
- package/src/types/outputs.ts +6 -0
- package/src/utils/index.ts +5 -0
- package/lib/.tsbuildinfo +0 -3
- package/lib/Interactions.d.ts +0 -24
- package/lib/Interactions.js +0 -123
- package/lib/Interactions.js.map +0 -1
- package/lib/Providers/AWSLexProvider.d.ts +0 -24
- package/lib/Providers/AWSLexProvider.js +0 -187
- package/lib/Providers/AWSLexProvider.js.map +0 -1
- package/lib/Providers/AWSLexProviderHelper/commonUtils.d.ts +0 -1
- package/lib/Providers/AWSLexProviderHelper/commonUtils.js +0 -29
- package/lib/Providers/AWSLexProviderHelper/commonUtils.js.map +0 -1
- package/lib/Providers/AWSLexProviderHelper/utils.js +0 -38
- package/lib/Providers/AWSLexProviderHelper/utils.js.map +0 -1
- package/lib/Providers/AWSLexProviderHelper/utils.native.js +0 -55
- package/lib/Providers/AWSLexProviderHelper/utils.native.js.map +0 -1
- package/lib/Providers/AWSLexV2Provider.d.ts +0 -58
- package/lib/Providers/AWSLexV2Provider.js +0 -282
- package/lib/Providers/AWSLexV2Provider.js.map +0 -1
- package/lib/Providers/InteractionsProvider.d.ts +0 -11
- package/lib/Providers/InteractionsProvider.js +0 -32
- package/lib/Providers/InteractionsProvider.js.map +0 -1
- package/lib/Providers/index.d.ts +0 -3
- package/lib/Providers/index.js +0 -11
- package/lib/Providers/index.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/Interactions.js.map +0 -1
- package/lib/types/Provider.d.ts +0 -12
- package/lib/types/Provider.js +0 -3
- package/lib/types/Provider.js.map +0 -1
- package/lib/types/Providers/AWSLexProvider.d.ts +0 -10
- package/lib/types/Providers/AWSLexProvider.js +0 -3
- package/lib/types/Providers/AWSLexProvider.js.map +0 -1
- package/lib/types/Providers/AWSLexV2Provider.d.ts +0 -12
- package/lib/types/Providers/AWSLexV2Provider.js +0 -3
- package/lib/types/Providers/AWSLexV2Provider.js.map +0 -1
- package/lib/types/Response.d.ts +0 -3
- package/lib/types/Response.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/Interactions.d.ts +0 -24
- package/lib-esm/Interactions.js +0 -121
- package/lib-esm/Interactions.js.map +0 -1
- package/lib-esm/Providers/AWSLexProvider.d.ts +0 -24
- package/lib-esm/Providers/AWSLexProvider.js +0 -185
- package/lib-esm/Providers/AWSLexProvider.js.map +0 -1
- package/lib-esm/Providers/AWSLexProviderHelper/commonUtils.d.ts +0 -1
- package/lib-esm/Providers/AWSLexProviderHelper/commonUtils.js +0 -27
- package/lib-esm/Providers/AWSLexProviderHelper/commonUtils.js.map +0 -1
- package/lib-esm/Providers/AWSLexProviderHelper/utils.js +0 -36
- package/lib-esm/Providers/AWSLexProviderHelper/utils.js.map +0 -1
- package/lib-esm/Providers/AWSLexProviderHelper/utils.native.js +0 -53
- package/lib-esm/Providers/AWSLexProviderHelper/utils.native.js.map +0 -1
- package/lib-esm/Providers/AWSLexV2Provider.d.ts +0 -58
- package/lib-esm/Providers/AWSLexV2Provider.js +0 -280
- package/lib-esm/Providers/AWSLexV2Provider.js.map +0 -1
- package/lib-esm/Providers/InteractionsProvider.d.ts +0 -11
- package/lib-esm/Providers/InteractionsProvider.js +0 -30
- package/lib-esm/Providers/InteractionsProvider.js.map +0 -1
- package/lib-esm/Providers/index.d.ts +0 -3
- package/lib-esm/Providers/index.js +0 -6
- package/lib-esm/Providers/index.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/types/Interactions.js.map +0 -1
- package/lib-esm/types/Provider.d.ts +0 -12
- package/lib-esm/types/Provider.js +0 -1
- package/lib-esm/types/Provider.js.map +0 -1
- package/lib-esm/types/Providers/AWSLexProvider.d.ts +0 -10
- package/lib-esm/types/Providers/AWSLexProvider.js +0 -1
- package/lib-esm/types/Providers/AWSLexProvider.js.map +0 -1
- package/lib-esm/types/Providers/AWSLexV2Provider.d.ts +0 -12
- package/lib-esm/types/Providers/AWSLexV2Provider.js +0 -1
- package/lib-esm/types/Providers/AWSLexV2Provider.js.map +0 -1
- package/lib-esm/types/Response.d.ts +0 -3
- package/lib-esm/types/Response.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
- package/src/Interactions.ts +0 -162
- package/src/Providers/AWSLexProvider.ts +0 -212
- package/src/Providers/InteractionsProvider.ts +0 -49
- package/src/Providers/index.ts +0 -5
- package/src/types/Provider.ts +0 -26
- package/src/types/Providers/AWSLexProvider.ts +0 -13
- /package/lib/{Providers/AWSLexProviderHelper → utils}/utils.d.ts +0 -0
- /package/lib/{Providers/AWSLexProviderHelper → utils}/utils.native.d.ts +0 -0
- /package/lib-esm/{Providers/AWSLexProviderHelper → utils}/utils.d.ts +0 -0
- /package/lib-esm/{Providers/AWSLexProviderHelper → utils}/utils.native.d.ts +0 -0
- /package/src/{Providers/AWSLexProviderHelper → utils}/commonUtils.ts +0 -0
- /package/src/{Providers/AWSLexProviderHelper → utils}/utils.native.ts +0 -0
- /package/src/{Providers/AWSLexProviderHelper → utils}/utils.ts +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.InteractionsError = void 0;
|
|
6
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
class InteractionsError extends utils_1.AmplifyError {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super(params);
|
|
10
|
+
// Hack for making the custom error class work when transpiled to es5
|
|
11
|
+
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
12
|
+
this.constructor = InteractionsError;
|
|
13
|
+
Object.setPrototypeOf(this, InteractionsError.prototype);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.InteractionsError = InteractionsError;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.assertValidationError = void 0;
|
|
6
|
+
const validation_1 = require("./validation");
|
|
7
|
+
const InteractionsError_1 = require("./InteractionsError");
|
|
8
|
+
function assertValidationError(assertion, name, message) {
|
|
9
|
+
if (!assertion) {
|
|
10
|
+
const { message: defaultMessage, recoverySuggestion } = validation_1.validationErrorMap[name];
|
|
11
|
+
throw new InteractionsError_1.InteractionsError({
|
|
12
|
+
name,
|
|
13
|
+
message: message ?? defaultMessage,
|
|
14
|
+
recoverySuggestion,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.assertValidationError = assertValidationError;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.InteractionsValidationErrorCode = exports.assertValidationError = void 0;
|
|
6
|
+
var assertValidationError_1 = require("./assertValidationError");
|
|
7
|
+
Object.defineProperty(exports, "assertValidationError", { enumerable: true, get: function () { return assertValidationError_1.assertValidationError; } });
|
|
8
|
+
var validation_1 = require("./validation");
|
|
9
|
+
Object.defineProperty(exports, "InteractionsValidationErrorCode", { enumerable: true, get: function () { return validation_1.InteractionsValidationErrorCode; } });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.validationErrorMap = exports.InteractionsValidationErrorCode = void 0;
|
|
6
|
+
var InteractionsValidationErrorCode;
|
|
7
|
+
(function (InteractionsValidationErrorCode) {
|
|
8
|
+
InteractionsValidationErrorCode["NoBotConfig"] = "NoBotConfig";
|
|
9
|
+
})(InteractionsValidationErrorCode || (exports.InteractionsValidationErrorCode = InteractionsValidationErrorCode = {}));
|
|
10
|
+
exports.validationErrorMap = {
|
|
11
|
+
[InteractionsValidationErrorCode.NoBotConfig]: {
|
|
12
|
+
message: 'Missing configuration for the bot',
|
|
13
|
+
},
|
|
14
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
export { Interactions } from './
|
|
2
|
-
export
|
|
3
|
-
export { AbstractInteractionsProvider } from './Providers/InteractionsProvider';
|
|
4
|
-
export { AWSLexProvider } from './Providers/AWSLexProvider';
|
|
5
|
-
export { AWSLexV2Provider } from './Providers/AWSLexV2Provider';
|
|
1
|
+
export { Interactions } from './lex-v2';
|
|
2
|
+
export { SendInput, OnCompleteInput, SendOutput } from './lex-v2/types';
|
package/lib/index.js
CHANGED
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.AbstractInteractionsProvider = InteractionsProvider_1.AbstractInteractionsProvider;
|
|
9
|
-
var AWSLexProvider_1 = require("./Providers/AWSLexProvider");
|
|
10
|
-
exports.AWSLexProvider = AWSLexProvider_1.AWSLexProvider;
|
|
11
|
-
var AWSLexV2Provider_1 = require("./Providers/AWSLexV2Provider");
|
|
12
|
-
exports.AWSLexV2Provider = AWSLexV2Provider_1.AWSLexV2Provider;
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
|
5
|
+
exports.Interactions = void 0;
|
|
6
|
+
var lex_v2_1 = require("./lex-v2");
|
|
7
|
+
Object.defineProperty(exports, "Interactions", { enumerable: true, get: function () { return lex_v2_1.Interactions; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { InteractionsOnCompleteCallback, InteractionsMessage, InteractionsResponse } from '../types/Interactions';
|
|
2
|
+
import { PostContentCommandOutput, PostTextCommandOutput } from '@aws-sdk/client-lex-runtime-service';
|
|
3
|
+
import { AWSLexProviderOption } from './types';
|
|
4
|
+
interface PostContentCommandOutputFormatted extends Omit<PostContentCommandOutput, 'audioStream'> {
|
|
5
|
+
audioStream?: Uint8Array;
|
|
6
|
+
}
|
|
7
|
+
type AWSLexProviderSendResponse = PostTextCommandOutput | PostContentCommandOutputFormatted;
|
|
8
|
+
declare class AWSLexProvider {
|
|
9
|
+
private readonly _botsCompleteCallback;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated
|
|
12
|
+
* This is used internally by 'sendMessage' to call onComplete callback
|
|
13
|
+
* for a bot if configured
|
|
14
|
+
*/
|
|
15
|
+
reportBotStatus(data: AWSLexProviderSendResponse, { name }: AWSLexProviderOption): void;
|
|
16
|
+
sendMessage(botConfig: AWSLexProviderOption, message: string | InteractionsMessage): Promise<InteractionsResponse>;
|
|
17
|
+
onComplete({ name }: AWSLexProviderOption, callback: InteractionsOnCompleteCallback): void;
|
|
18
|
+
}
|
|
19
|
+
export declare const lexProvider: AWSLexProvider;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lexProvider = void 0;
|
|
4
|
+
const client_lex_runtime_service_1 = require("@aws-sdk/client-lex-runtime-service");
|
|
5
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const utils_2 = require("../utils");
|
|
8
|
+
const logger = new core_1.ConsoleLogger('AWSLexProvider');
|
|
9
|
+
class AWSLexProvider {
|
|
10
|
+
constructor() {
|
|
11
|
+
this._botsCompleteCallback = {};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated
|
|
15
|
+
* This is used internally by 'sendMessage' to call onComplete callback
|
|
16
|
+
* for a bot if configured
|
|
17
|
+
*/
|
|
18
|
+
reportBotStatus(data, { name }) {
|
|
19
|
+
const callback = this._botsCompleteCallback[name];
|
|
20
|
+
if (!callback) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// Check if state is fulfilled to resolve onFullfilment promise
|
|
24
|
+
logger.debug('postContent state', data.dialogState);
|
|
25
|
+
switch (data.dialogState) {
|
|
26
|
+
case client_lex_runtime_service_1.DialogState.READY_FOR_FULFILLMENT:
|
|
27
|
+
case client_lex_runtime_service_1.DialogState.FULFILLED:
|
|
28
|
+
callback(undefined, data);
|
|
29
|
+
break;
|
|
30
|
+
case client_lex_runtime_service_1.DialogState.FAILED:
|
|
31
|
+
callback(new Error('Bot conversation failed'));
|
|
32
|
+
break;
|
|
33
|
+
default:
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async sendMessage(botConfig, message) {
|
|
38
|
+
// check if credentials are present
|
|
39
|
+
let session;
|
|
40
|
+
try {
|
|
41
|
+
session = await (0, core_1.fetchAuthSession)();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return Promise.reject('No credentials');
|
|
45
|
+
}
|
|
46
|
+
const { name, region, alias } = botConfig;
|
|
47
|
+
const client = new client_lex_runtime_service_1.LexRuntimeServiceClient({
|
|
48
|
+
region,
|
|
49
|
+
credentials: session.credentials,
|
|
50
|
+
customUserAgent: (0, utils_1.getAmplifyUserAgentObject)(),
|
|
51
|
+
});
|
|
52
|
+
let params;
|
|
53
|
+
if (typeof message === 'string') {
|
|
54
|
+
params = {
|
|
55
|
+
botAlias: alias,
|
|
56
|
+
botName: name,
|
|
57
|
+
inputText: message,
|
|
58
|
+
userId: session.identityId,
|
|
59
|
+
};
|
|
60
|
+
logger.debug('postText to lex', message);
|
|
61
|
+
try {
|
|
62
|
+
const postTextCommand = new client_lex_runtime_service_1.PostTextCommand(params);
|
|
63
|
+
const data = await client.send(postTextCommand);
|
|
64
|
+
this.reportBotStatus(data, botConfig);
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
return Promise.reject(err);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const { content, options: { messageType }, } = message;
|
|
73
|
+
if (messageType === 'voice') {
|
|
74
|
+
if (typeof content !== 'object') {
|
|
75
|
+
return Promise.reject('invalid content type');
|
|
76
|
+
}
|
|
77
|
+
const inputStream = content instanceof Uint8Array ? content : await (0, utils_2.convert)(content);
|
|
78
|
+
params = {
|
|
79
|
+
botAlias: alias,
|
|
80
|
+
botName: name,
|
|
81
|
+
contentType: 'audio/x-l16; sample-rate=16000; channel-count=1',
|
|
82
|
+
userId: session.identityId,
|
|
83
|
+
accept: 'audio/mpeg',
|
|
84
|
+
inputStream,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (typeof content !== 'string')
|
|
89
|
+
return Promise.reject('invalid content type');
|
|
90
|
+
params = {
|
|
91
|
+
botAlias: alias,
|
|
92
|
+
botName: name,
|
|
93
|
+
contentType: 'text/plain; charset=utf-8',
|
|
94
|
+
inputStream: content,
|
|
95
|
+
userId: session.identityId,
|
|
96
|
+
accept: 'audio/mpeg',
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
logger.debug('postContent to lex', message);
|
|
100
|
+
try {
|
|
101
|
+
const postContentCommand = new client_lex_runtime_service_1.PostContentCommand(params);
|
|
102
|
+
const data = await client.send(postContentCommand);
|
|
103
|
+
const audioArray = data.audioStream
|
|
104
|
+
? await (0, utils_2.convert)(data.audioStream)
|
|
105
|
+
: undefined;
|
|
106
|
+
const response = { ...data, ...{ audioStream: audioArray } };
|
|
107
|
+
this.reportBotStatus(response, botConfig);
|
|
108
|
+
return response;
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
return Promise.reject(err);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
onComplete({ name }, callback) {
|
|
116
|
+
this._botsCompleteCallback[name] = callback;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.lexProvider = new AWSLexProvider();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.onComplete = exports.send = void 0;
|
|
6
|
+
var send_1 = require("./send");
|
|
7
|
+
Object.defineProperty(exports, "send", { enumerable: true, get: function () { return send_1.send; } });
|
|
8
|
+
var onComplete_1 = require("./onComplete");
|
|
9
|
+
Object.defineProperty(exports, "onComplete", { enumerable: true, get: function () { return onComplete_1.onComplete; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.onComplete = void 0;
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const AWSLexProvider_1 = require("../AWSLexProvider");
|
|
8
|
+
const errors_1 = require("../../errors");
|
|
9
|
+
const onComplete = (input) => {
|
|
10
|
+
const { botName, callback } = input;
|
|
11
|
+
const botConfig = (0, utils_1.resolveBotConfig)(botName);
|
|
12
|
+
(0, errors_1.assertValidationError)(!!botConfig, errors_1.InteractionsValidationErrorCode.NoBotConfig, `Bot ${botName} does not exist.`);
|
|
13
|
+
AWSLexProvider_1.lexProvider.onComplete(botConfig, callback);
|
|
14
|
+
};
|
|
15
|
+
exports.onComplete = onComplete;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.send = void 0;
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const AWSLexProvider_1 = require("../AWSLexProvider");
|
|
8
|
+
const errors_1 = require("../../errors");
|
|
9
|
+
const send = async (input) => {
|
|
10
|
+
const { botName, message } = input;
|
|
11
|
+
const botConfig = (0, utils_1.resolveBotConfig)(botName);
|
|
12
|
+
(0, errors_1.assertValidationError)(!!botConfig, errors_1.InteractionsValidationErrorCode.NoBotConfig, `Bot ${botName} does not exist.`);
|
|
13
|
+
return AWSLexProvider_1.lexProvider.sendMessage(botConfig, message);
|
|
14
|
+
};
|
|
15
|
+
exports.send = send;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.Interactions = void 0;
|
|
6
|
+
const apis_1 = require("./apis");
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated recommend to migrate to AWS Lex V2 instead
|
|
9
|
+
* */
|
|
10
|
+
exports.Interactions = {
|
|
11
|
+
send: apis_1.send,
|
|
12
|
+
onComplete: apis_1.onComplete,
|
|
13
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SendInput, OnCompleteInput } from './inputs';
|
|
2
|
+
import { SendOutput } from './outputs';
|
|
3
|
+
export interface AWSLexProviderOption {
|
|
4
|
+
name: string;
|
|
5
|
+
alias: string;
|
|
6
|
+
region: string;
|
|
7
|
+
}
|
|
8
|
+
export interface IInteractions {
|
|
9
|
+
send(input: SendInput): Promise<SendOutput>;
|
|
10
|
+
onComplete(input: OnCompleteInput): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InteractionsSendInput, InteractionsOnCompleteInput } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Input type for LexV1 send API.
|
|
4
|
+
*/
|
|
5
|
+
export type SendInput = InteractionsSendInput;
|
|
6
|
+
/**
|
|
7
|
+
* Input type for LexV1 onComplete API.
|
|
8
|
+
*/
|
|
9
|
+
export type OnCompleteInput = InteractionsOnCompleteInput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolveBotConfig } from './resolveBotConfig';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.resolveBotConfig = void 0;
|
|
6
|
+
var resolveBotConfig_1 = require("./resolveBotConfig");
|
|
7
|
+
Object.defineProperty(exports, "resolveBotConfig", { enumerable: true, get: function () { return resolveBotConfig_1.resolveBotConfig; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.resolveBotConfig = void 0;
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const resolveBotConfig = (botName) => {
|
|
8
|
+
const { [botName]: botConfig = undefined } = core_1.Amplify.getConfig().Interactions?.LexV1 ?? {};
|
|
9
|
+
if (botConfig !== undefined) {
|
|
10
|
+
return { ...botConfig, name: botName };
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
exports.resolveBotConfig = resolveBotConfig;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { InteractionsOnCompleteCallback, InteractionsMessage, InteractionsResponse } from '../types/Interactions';
|
|
2
|
+
import { RecognizeTextCommandOutput, RecognizeUtteranceCommandOutput } from '@aws-sdk/client-lex-runtime-v2';
|
|
3
|
+
import { AWSLexV2ProviderOption } from './types';
|
|
4
|
+
interface RecognizeUtteranceCommandOutputFormatted extends Omit<RecognizeUtteranceCommandOutput, 'messages' | 'interpretations' | 'sessionState' | 'requestAttributes' | 'audioStream'> {
|
|
5
|
+
messages?: RecognizeTextCommandOutput['messages'];
|
|
6
|
+
sessionState?: RecognizeTextCommandOutput['sessionState'];
|
|
7
|
+
interpretations?: RecognizeTextCommandOutput['interpretations'];
|
|
8
|
+
requestAttributes?: RecognizeTextCommandOutput['requestAttributes'];
|
|
9
|
+
audioStream?: Uint8Array;
|
|
10
|
+
}
|
|
11
|
+
type AWSLexV2ProviderSendResponse = RecognizeTextCommandOutput | RecognizeUtteranceCommandOutputFormatted;
|
|
12
|
+
declare class AWSLexV2Provider {
|
|
13
|
+
private readonly _botsCompleteCallback;
|
|
14
|
+
private defaultSessionId;
|
|
15
|
+
/**
|
|
16
|
+
* Send a message to a bot
|
|
17
|
+
* @async
|
|
18
|
+
* @param {AWSLexV2ProviderOption} botConfig - Bot configuration for sending the message
|
|
19
|
+
* @param {string | InteractionsMessage} message - message to send to the bot
|
|
20
|
+
* @return {Promise<InteractionsResponse>} A promise resolves to the response from the bot
|
|
21
|
+
*/
|
|
22
|
+
sendMessage(botConfig: AWSLexV2ProviderOption, message: string | InteractionsMessage): Promise<InteractionsResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Attach a onComplete callback function to a bot.
|
|
25
|
+
* The callback is called once the bot's intent is fulfilled
|
|
26
|
+
* @param {AWSLexV2ProviderOption} botConfig - Bot configuration to attach the onComplete callback
|
|
27
|
+
* @param {InteractionsOnCompleteCallback} callback - called when Intent Fulfilled
|
|
28
|
+
*/
|
|
29
|
+
onComplete({ name }: AWSLexV2ProviderOption, callback: InteractionsOnCompleteCallback): void;
|
|
30
|
+
/**
|
|
31
|
+
* call onComplete callback for a bot if configured
|
|
32
|
+
*/
|
|
33
|
+
_reportBotStatus(data: AWSLexV2ProviderSendResponse, { name }: AWSLexV2ProviderOption): void;
|
|
34
|
+
/**
|
|
35
|
+
* Format UtteranceCommandOutput's response
|
|
36
|
+
* decompress attributes
|
|
37
|
+
* update audioStream format
|
|
38
|
+
*/
|
|
39
|
+
private _formatUtteranceCommandOutput;
|
|
40
|
+
/**
|
|
41
|
+
* handle client's `RecognizeTextCommand`
|
|
42
|
+
* used for sending simple text message
|
|
43
|
+
*/
|
|
44
|
+
private _handleRecognizeTextCommand;
|
|
45
|
+
/**
|
|
46
|
+
* handle client's `RecognizeUtteranceCommand`
|
|
47
|
+
* used for obj text or obj voice message
|
|
48
|
+
*/
|
|
49
|
+
private _handleRecognizeUtteranceCommand;
|
|
50
|
+
}
|
|
51
|
+
export declare const lexProvider: AWSLexV2Provider;
|
|
52
|
+
export {};
|