@aws-amplify/interactions 6.0.1-api-v6-models.9351bcf.0 → 6.0.1-api-v6-models.891fe0d.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/lib/errors/InteractionsError.js +7 -11
- package/lib/errors/assertValidationError.js +6 -6
- package/lib/errors/validation.js +3 -4
- package/lib/index.d.ts +1 -1
- package/lib/lex-v1/AWSLexProvider.d.ts +2 -2
- package/lib/lex-v1/AWSLexProvider.js +90 -124
- package/lib/lex-v1/apis/onComplete.d.ts +2 -2
- package/lib/lex-v1/apis/onComplete.js +7 -6
- package/lib/lex-v1/apis/send.d.ts +2 -2
- package/lib/lex-v1/apis/send.js +9 -12
- package/lib/lex-v1/index.d.ts +2 -1
- package/lib/lex-v1/index.js +1 -1
- package/lib/lex-v1/types/AWSLexProviderOption.d.ts +6 -0
- package/lib/lex-v1/types/index.d.ts +2 -0
- package/lib/lex-v1/types/inputs.d.ts +9 -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/resolveBotConfig.js +4 -6
- package/lib/lex-v2/AWSLexV2Provider.d.ts +3 -3
- package/lib/lex-v2/AWSLexV2Provider.js +115 -174
- package/lib/lex-v2/apis/onComplete.d.ts +2 -2
- package/lib/lex-v2/apis/onComplete.js +7 -6
- package/lib/lex-v2/apis/send.d.ts +2 -2
- package/lib/lex-v2/apis/send.js +9 -12
- package/lib/lex-v2/index.d.ts +2 -1
- package/lib/lex-v2/index.js +1 -1
- package/lib/lex-v2/types/AWSLexV2ProviderOption.d.ts +6 -0
- package/lib/lex-v2/types/index.d.ts +2 -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/resolveBotConfig.js +4 -6
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/Interactions.d.ts +4 -5
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.js +2 -0
- 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.js +13 -24
- package/lib/utils/utils.js +22 -31
- package/lib/utils/utils.native.js +33 -46
- package/lib-esm/errors/InteractionsError.js +6 -11
- package/lib-esm/errors/assertValidationError.js +4 -4
- package/lib-esm/errors/validation.js +3 -4
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/lex-v1/AWSLexProvider.d.ts +2 -2
- package/lib-esm/lex-v1/AWSLexProvider.js +87 -121
- package/lib-esm/lex-v1/apis/onComplete.d.ts +2 -2
- package/lib-esm/lex-v1/apis/onComplete.js +4 -3
- package/lib-esm/lex-v1/apis/send.d.ts +2 -2
- package/lib-esm/lex-v1/apis/send.js +6 -9
- package/lib-esm/lex-v1/index.d.ts +2 -1
- package/lib-esm/lex-v1/index.js +3 -3
- package/lib-esm/lex-v1/types/AWSLexProviderOption.d.ts +6 -0
- package/lib-esm/lex-v1/types/index.d.ts +2 -0
- package/lib-esm/lex-v1/types/inputs.d.ts +9 -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/resolveBotConfig.js +3 -5
- package/lib-esm/lex-v2/AWSLexV2Provider.d.ts +3 -3
- package/lib-esm/lex-v2/AWSLexV2Provider.js +111 -170
- package/lib-esm/lex-v2/apis/onComplete.d.ts +2 -2
- package/lib-esm/lex-v2/apis/onComplete.js +4 -3
- package/lib-esm/lex-v2/apis/send.d.ts +2 -2
- package/lib-esm/lex-v2/apis/send.js +6 -9
- package/lib-esm/lex-v2/index.d.ts +2 -1
- package/lib-esm/lex-v2/index.js +3 -3
- package/lib-esm/lex-v2/types/AWSLexV2ProviderOption.d.ts +6 -0
- package/lib-esm/lex-v2/types/index.d.ts +2 -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/resolveBotConfig.js +3 -5
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/Interactions.d.ts +4 -5
- package/lib-esm/types/index.d.ts +2 -2
- package/lib-esm/types/index.js +2 -0
- 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.js +12 -23
- package/lib-esm/utils/utils.js +21 -30
- package/lib-esm/utils/utils.native.js +31 -44
- package/package.json +4 -7
- package/src/index.ts +1 -7
- package/src/lex-v1/AWSLexProvider.ts +10 -5
- package/src/lex-v1/apis/onComplete.ts +3 -5
- package/src/lex-v1/apis/send.ts +3 -5
- package/src/lex-v1/index.ts +2 -1
- package/src/lex-v1/types/AWSLexProviderOption.ts +8 -0
- package/src/lex-v1/types/index.ts +2 -0
- package/src/lex-v1/types/inputs.ts +17 -0
- package/src/lex-v1/types/outputs.ts +9 -0
- package/src/lex-v2/AWSLexV2Provider.ts +8 -6
- package/src/lex-v2/apis/onComplete.ts +3 -5
- package/src/lex-v2/apis/send.ts +3 -5
- package/src/lex-v2/index.ts +2 -1
- package/src/lex-v2/types/AWSLexV2ProviderOption.ts +8 -0
- package/src/lex-v2/types/index.ts +2 -0
- package/src/lex-v2/types/inputs.ts +17 -0
- package/src/lex-v2/types/outputs.ts +9 -0
- package/src/types/Interactions.ts +8 -9
- package/src/types/index.ts +3 -6
- package/src/types/inputs.ts +17 -0
- package/src/types/outputs.ts +6 -0
- package/lib/types/Response.d.ts +0 -4
- package/lib-esm/types/Response.d.ts +0 -4
- package/src/types/Response.ts +0 -11
- /package/lib/{types/Response.js → lex-v1/types/inputs.js} +0 -0
- /package/lib-esm/{types/Response.js → lex-v1/types/inputs.js} +0 -0
|
@@ -3,18 +3,14 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.InteractionsError = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function InteractionsError(params) {
|
|
11
|
-
var _this = _super.call(this, params) || this;
|
|
6
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
class InteractionsError extends utils_1.AmplifyError {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super(params);
|
|
12
10
|
// Hack for making the custom error class work when transpiled to es5
|
|
13
11
|
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
14
|
-
|
|
15
|
-
Object.setPrototypeOf(
|
|
16
|
-
return _this;
|
|
12
|
+
this.constructor = InteractionsError;
|
|
13
|
+
Object.setPrototypeOf(this, InteractionsError.prototype);
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
}(utils_1.AmplifyError));
|
|
15
|
+
}
|
|
20
16
|
exports.InteractionsError = InteractionsError;
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.assertValidationError = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const validation_1 = require("./validation");
|
|
7
|
+
const InteractionsError_1 = require("./InteractionsError");
|
|
8
8
|
function assertValidationError(assertion, name, message) {
|
|
9
9
|
if (!assertion) {
|
|
10
|
-
|
|
10
|
+
const { message: defaultMessage, recoverySuggestion } = validation_1.validationErrorMap[name];
|
|
11
11
|
throw new InteractionsError_1.InteractionsError({
|
|
12
|
-
name
|
|
13
|
-
message: message
|
|
14
|
-
recoverySuggestion
|
|
12
|
+
name,
|
|
13
|
+
message: message ?? defaultMessage,
|
|
14
|
+
recoverySuggestion,
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
}
|
package/lib/errors/validation.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
var _a;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
5
|
exports.validationErrorMap = exports.InteractionsValidationErrorCode = void 0;
|
|
7
6
|
var InteractionsValidationErrorCode;
|
|
8
7
|
(function (InteractionsValidationErrorCode) {
|
|
9
8
|
InteractionsValidationErrorCode["NoBotConfig"] = "NoBotConfig";
|
|
10
9
|
})(InteractionsValidationErrorCode || (exports.InteractionsValidationErrorCode = InteractionsValidationErrorCode = {}));
|
|
11
|
-
exports.validationErrorMap =
|
|
12
|
-
|
|
10
|
+
exports.validationErrorMap = {
|
|
11
|
+
[InteractionsValidationErrorCode.NoBotConfig]: {
|
|
13
12
|
message: 'Missing configuration for the bot',
|
|
14
13
|
},
|
|
15
|
-
|
|
14
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InteractionsOnCompleteCallback, InteractionsMessage, InteractionsResponse } from '../types/Interactions';
|
|
2
2
|
import { PostContentCommandOutput, PostTextCommandOutput } from '@aws-sdk/client-lex-runtime-service';
|
|
3
3
|
import { AWSLexProviderOption } from './types';
|
|
4
4
|
interface PostContentCommandOutputFormatted extends Omit<PostContentCommandOutput, 'audioStream'> {
|
|
@@ -14,7 +14,7 @@ declare class AWSLexProvider {
|
|
|
14
14
|
*/
|
|
15
15
|
reportBotStatus(data: AWSLexProviderSendResponse, { name }: AWSLexProviderOption): void;
|
|
16
16
|
sendMessage(botConfig: AWSLexProviderOption, message: string | InteractionsMessage): Promise<InteractionsResponse>;
|
|
17
|
-
onComplete({ name }: AWSLexProviderOption, callback:
|
|
17
|
+
onComplete({ name }: AWSLexProviderOption, callback: InteractionsOnCompleteCallback): void;
|
|
18
18
|
}
|
|
19
19
|
export declare const lexProvider: AWSLexProvider;
|
|
20
20
|
export {};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.lexProvider = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function AWSLexProvider() {
|
|
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() {
|
|
12
11
|
this._botsCompleteCallback = {};
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
@@ -16,9 +15,8 @@ var AWSLexProvider = /** @class */ (function () {
|
|
|
16
15
|
* This is used internally by 'sendMessage' to call onComplete callback
|
|
17
16
|
* for a bot if configured
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var callback = this._botsCompleteCallback[name];
|
|
18
|
+
reportBotStatus(data, { name }) {
|
|
19
|
+
const callback = this._botsCompleteCallback[name];
|
|
22
20
|
if (!callback) {
|
|
23
21
|
return;
|
|
24
22
|
}
|
|
@@ -35,119 +33,87 @@ var AWSLexProvider = /** @class */ (function () {
|
|
|
35
33
|
default:
|
|
36
34
|
break;
|
|
37
35
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
case 3:
|
|
54
|
-
name = botConfig.name, region = botConfig.region, alias = botConfig.alias;
|
|
55
|
-
client = new client_lex_runtime_service_1.LexRuntimeServiceClient({
|
|
56
|
-
region: region,
|
|
57
|
-
credentials: session.credentials,
|
|
58
|
-
customUserAgent: (0, utils_1.getAmplifyUserAgentObject)(),
|
|
59
|
-
});
|
|
60
|
-
if (!(typeof message === 'string')) return [3 /*break*/, 8];
|
|
61
|
-
params = {
|
|
62
|
-
botAlias: alias,
|
|
63
|
-
botName: name,
|
|
64
|
-
inputText: message,
|
|
65
|
-
userId: session.identityId,
|
|
66
|
-
};
|
|
67
|
-
logger.debug('postText to lex', message);
|
|
68
|
-
_c.label = 4;
|
|
69
|
-
case 4:
|
|
70
|
-
_c.trys.push([4, 6, , 7]);
|
|
71
|
-
postTextCommand = new client_lex_runtime_service_1.PostTextCommand(params);
|
|
72
|
-
return [4 /*yield*/, client.send(postTextCommand)];
|
|
73
|
-
case 5:
|
|
74
|
-
data = _c.sent();
|
|
75
|
-
this.reportBotStatus(data, botConfig);
|
|
76
|
-
return [2 /*return*/, data];
|
|
77
|
-
case 6:
|
|
78
|
-
err_1 = _c.sent();
|
|
79
|
-
return [2 /*return*/, Promise.reject(err_1)];
|
|
80
|
-
case 7: return [3 /*break*/, 20];
|
|
81
|
-
case 8:
|
|
82
|
-
content = message.content, messageType = message.options.messageType;
|
|
83
|
-
if (!(messageType === 'voice')) return [3 /*break*/, 12];
|
|
84
|
-
if (typeof content !== 'object') {
|
|
85
|
-
return [2 /*return*/, Promise.reject('invalid content type')];
|
|
86
|
-
}
|
|
87
|
-
if (!(content instanceof Uint8Array)) return [3 /*break*/, 9];
|
|
88
|
-
_a = content;
|
|
89
|
-
return [3 /*break*/, 11];
|
|
90
|
-
case 9: return [4 /*yield*/, (0, utils_2.convert)(content)];
|
|
91
|
-
case 10:
|
|
92
|
-
_a = _c.sent();
|
|
93
|
-
_c.label = 11;
|
|
94
|
-
case 11:
|
|
95
|
-
inputStream = _a;
|
|
96
|
-
params = {
|
|
97
|
-
botAlias: alias,
|
|
98
|
-
botName: name,
|
|
99
|
-
contentType: 'audio/x-l16; sample-rate=16000; channel-count=1',
|
|
100
|
-
userId: session.identityId,
|
|
101
|
-
accept: 'audio/mpeg',
|
|
102
|
-
inputStream: inputStream,
|
|
103
|
-
};
|
|
104
|
-
return [3 /*break*/, 13];
|
|
105
|
-
case 12:
|
|
106
|
-
if (typeof content !== 'string')
|
|
107
|
-
return [2 /*return*/, Promise.reject('invalid content type')];
|
|
108
|
-
params = {
|
|
109
|
-
botAlias: alias,
|
|
110
|
-
botName: name,
|
|
111
|
-
contentType: 'text/plain; charset=utf-8',
|
|
112
|
-
inputStream: content,
|
|
113
|
-
userId: session.identityId,
|
|
114
|
-
accept: 'audio/mpeg',
|
|
115
|
-
};
|
|
116
|
-
_c.label = 13;
|
|
117
|
-
case 13:
|
|
118
|
-
logger.debug('postContent to lex', message);
|
|
119
|
-
_c.label = 14;
|
|
120
|
-
case 14:
|
|
121
|
-
_c.trys.push([14, 19, , 20]);
|
|
122
|
-
postContentCommand = new client_lex_runtime_service_1.PostContentCommand(params);
|
|
123
|
-
return [4 /*yield*/, client.send(postContentCommand)];
|
|
124
|
-
case 15:
|
|
125
|
-
data = _c.sent();
|
|
126
|
-
if (!data.audioStream) return [3 /*break*/, 17];
|
|
127
|
-
return [4 /*yield*/, (0, utils_2.convert)(data.audioStream)];
|
|
128
|
-
case 16:
|
|
129
|
-
_b = _c.sent();
|
|
130
|
-
return [3 /*break*/, 18];
|
|
131
|
-
case 17:
|
|
132
|
-
_b = undefined;
|
|
133
|
-
_c.label = 18;
|
|
134
|
-
case 18:
|
|
135
|
-
audioArray = _b;
|
|
136
|
-
response = tslib_1.__assign(tslib_1.__assign({}, data), { audioStream: audioArray });
|
|
137
|
-
this.reportBotStatus(response, botConfig);
|
|
138
|
-
return [2 /*return*/, response];
|
|
139
|
-
case 19:
|
|
140
|
-
err_2 = _c.sent();
|
|
141
|
-
return [2 /*return*/, Promise.reject(err_2)];
|
|
142
|
-
case 20: return [2 /*return*/];
|
|
143
|
-
}
|
|
144
|
-
});
|
|
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)(),
|
|
145
51
|
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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) {
|
|
149
116
|
this._botsCompleteCallback[name] = callback;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
}());
|
|
117
|
+
}
|
|
118
|
+
}
|
|
153
119
|
exports.lexProvider = new AWSLexProvider();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const onComplete: (
|
|
1
|
+
import { OnCompleteInput } from '../types';
|
|
2
|
+
export declare const onComplete: (input: OnCompleteInput) => void;
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.onComplete = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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.`);
|
|
12
13
|
AWSLexProvider_1.lexProvider.onComplete(botConfig, callback);
|
|
13
14
|
};
|
|
14
15
|
exports.onComplete = onComplete;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const send: (
|
|
1
|
+
import { SendInput, SendOutput } from '../types';
|
|
2
|
+
export declare const send: (input: SendInput) => Promise<SendOutput>;
|
package/lib/lex-v1/apis/send.js
CHANGED
|
@@ -3,16 +3,13 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.send = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return [2 /*return*/, AWSLexProvider_1.lexProvider.sendMessage(botConfig, message)];
|
|
16
|
-
});
|
|
17
|
-
}); };
|
|
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
|
+
};
|
|
18
15
|
exports.send = send;
|
package/lib/lex-v1/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { IInteractions } from '
|
|
1
|
+
import { IInteractions } from './types/AWSLexProviderOption';
|
|
2
2
|
/**
|
|
3
3
|
* @deprecated recommend to migrate to AWS Lex V2 instead
|
|
4
4
|
* */
|
|
5
5
|
export declare const Interactions: IInteractions;
|
|
6
|
+
export { SendInput, OnCompleteInput, SendOutput } from './types';
|
package/lib/lex-v1/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.Interactions = void 0;
|
|
6
|
-
|
|
6
|
+
const apis_1 = require("./apis");
|
|
7
7
|
/**
|
|
8
8
|
* @deprecated recommend to migrate to AWS Lex V2 instead
|
|
9
9
|
* */
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { SendInput, OnCompleteInput } from './inputs';
|
|
2
|
+
import { SendOutput } from './outputs';
|
|
1
3
|
export interface AWSLexProviderOption {
|
|
2
4
|
name: string;
|
|
3
5
|
alias: string;
|
|
4
6
|
region: string;
|
|
5
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;
|
|
@@ -3,13 +3,11 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.resolveBotConfig = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _a, _b;
|
|
10
|
-
var _c = (_b = (_a = core_1.Amplify.getConfig().Interactions) === null || _a === void 0 ? void 0 : _a.LexV1) !== null && _b !== void 0 ? _b : {}, _d = botName, _e = _c[_d], botConfig = _e === void 0 ? undefined : _e;
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const resolveBotConfig = (botName) => {
|
|
8
|
+
const { [botName]: botConfig = undefined } = core_1.Amplify.getConfig().Interactions?.LexV1 ?? {};
|
|
11
9
|
if (botConfig !== undefined) {
|
|
12
|
-
return
|
|
10
|
+
return { ...botConfig, name: botName };
|
|
13
11
|
}
|
|
14
12
|
};
|
|
15
13
|
exports.resolveBotConfig = resolveBotConfig;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InteractionsOnCompleteCallback, InteractionsMessage, InteractionsResponse } from '../types/Interactions';
|
|
2
2
|
import { RecognizeTextCommandOutput, RecognizeUtteranceCommandOutput } from '@aws-sdk/client-lex-runtime-v2';
|
|
3
3
|
import { AWSLexV2ProviderOption } from './types';
|
|
4
4
|
interface RecognizeUtteranceCommandOutputFormatted extends Omit<RecognizeUtteranceCommandOutput, 'messages' | 'interpretations' | 'sessionState' | 'requestAttributes' | 'audioStream'> {
|
|
@@ -24,9 +24,9 @@ declare class AWSLexV2Provider {
|
|
|
24
24
|
* Attach a onComplete callback function to a bot.
|
|
25
25
|
* The callback is called once the bot's intent is fulfilled
|
|
26
26
|
* @param {AWSLexV2ProviderOption} botConfig - Bot configuration to attach the onComplete callback
|
|
27
|
-
* @param {
|
|
27
|
+
* @param {InteractionsOnCompleteCallback} callback - called when Intent Fulfilled
|
|
28
28
|
*/
|
|
29
|
-
onComplete({ name }: AWSLexV2ProviderOption, callback:
|
|
29
|
+
onComplete({ name }: AWSLexV2ProviderOption, callback: InteractionsOnCompleteCallback): void;
|
|
30
30
|
/**
|
|
31
31
|
* call onComplete callback for a bot if configured
|
|
32
32
|
*/
|