@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
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lexProvider = void 0;
|
|
4
|
+
const client_lex_runtime_v2_1 = require("@aws-sdk/client-lex-runtime-v2");
|
|
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 uuid_1 = require("uuid");
|
|
9
|
+
const logger = new core_1.ConsoleLogger('AWSLexV2Provider');
|
|
10
|
+
class AWSLexV2Provider {
|
|
11
|
+
constructor() {
|
|
12
|
+
this._botsCompleteCallback = {};
|
|
13
|
+
this.defaultSessionId = (0, uuid_1.v4)();
|
|
14
|
+
}
|
|
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
|
+
async sendMessage(botConfig, message) {
|
|
23
|
+
// check if credentials are present
|
|
24
|
+
let session;
|
|
25
|
+
try {
|
|
26
|
+
session = await (0, core_1.fetchAuthSession)();
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return Promise.reject('No credentials');
|
|
30
|
+
}
|
|
31
|
+
const { region, aliasId, localeId, botId } = botConfig;
|
|
32
|
+
const client = new client_lex_runtime_v2_1.LexRuntimeV2Client({
|
|
33
|
+
region,
|
|
34
|
+
credentials: session.credentials,
|
|
35
|
+
customUserAgent: (0, utils_1.getAmplifyUserAgentObject)(),
|
|
36
|
+
});
|
|
37
|
+
let response;
|
|
38
|
+
// common base params for all requests
|
|
39
|
+
const reqBaseParams = {
|
|
40
|
+
botAliasId: aliasId,
|
|
41
|
+
botId,
|
|
42
|
+
localeId,
|
|
43
|
+
sessionId: session.identityId ?? this.defaultSessionId,
|
|
44
|
+
};
|
|
45
|
+
if (typeof message === 'string') {
|
|
46
|
+
response = await this._handleRecognizeTextCommand(botConfig, message, reqBaseParams, client);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
response = await this._handleRecognizeUtteranceCommand(botConfig, message, reqBaseParams, client);
|
|
50
|
+
}
|
|
51
|
+
return response;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Attach a onComplete callback function to a bot.
|
|
55
|
+
* The callback is called once the bot's intent is fulfilled
|
|
56
|
+
* @param {AWSLexV2ProviderOption} botConfig - Bot configuration to attach the onComplete callback
|
|
57
|
+
* @param {InteractionsOnCompleteCallback} callback - called when Intent Fulfilled
|
|
58
|
+
*/
|
|
59
|
+
onComplete({ name }, callback) {
|
|
60
|
+
this._botsCompleteCallback[name] = callback;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* call onComplete callback for a bot if configured
|
|
64
|
+
*/
|
|
65
|
+
_reportBotStatus(data, { name }) {
|
|
66
|
+
const sessionState = data?.sessionState;
|
|
67
|
+
// Check if state is fulfilled to resolve onFullfilment promise
|
|
68
|
+
logger.debug('postContent state', sessionState?.intent?.state);
|
|
69
|
+
const callback = this._botsCompleteCallback[name];
|
|
70
|
+
if (!callback) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
switch (sessionState?.intent?.state) {
|
|
74
|
+
case client_lex_runtime_v2_1.IntentState.READY_FOR_FULFILLMENT:
|
|
75
|
+
case client_lex_runtime_v2_1.IntentState.FULFILLED:
|
|
76
|
+
callback(undefined, data);
|
|
77
|
+
break;
|
|
78
|
+
case client_lex_runtime_v2_1.IntentState.FAILED:
|
|
79
|
+
callback(new Error('Bot conversation failed'));
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Format UtteranceCommandOutput's response
|
|
87
|
+
* decompress attributes
|
|
88
|
+
* update audioStream format
|
|
89
|
+
*/
|
|
90
|
+
async _formatUtteranceCommandOutput(data) {
|
|
91
|
+
return {
|
|
92
|
+
...data,
|
|
93
|
+
messages: await (0, utils_2.unGzipBase64AsJson)(data.messages),
|
|
94
|
+
sessionState: await (0, utils_2.unGzipBase64AsJson)(data.sessionState),
|
|
95
|
+
interpretations: await (0, utils_2.unGzipBase64AsJson)(data.interpretations),
|
|
96
|
+
requestAttributes: await (0, utils_2.unGzipBase64AsJson)(data.requestAttributes),
|
|
97
|
+
inputTranscript: await (0, utils_2.unGzipBase64AsJson)(data.inputTranscript),
|
|
98
|
+
audioStream: data.audioStream
|
|
99
|
+
? await (0, utils_2.convert)(data.audioStream)
|
|
100
|
+
: undefined,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* handle client's `RecognizeTextCommand`
|
|
105
|
+
* used for sending simple text message
|
|
106
|
+
*/
|
|
107
|
+
async _handleRecognizeTextCommand(botConfig, data, baseParams, client) {
|
|
108
|
+
logger.debug('postText to lex2', data);
|
|
109
|
+
const params = {
|
|
110
|
+
...baseParams,
|
|
111
|
+
text: data,
|
|
112
|
+
};
|
|
113
|
+
try {
|
|
114
|
+
const recognizeTextCommand = new client_lex_runtime_v2_1.RecognizeTextCommand(params);
|
|
115
|
+
const data = await client.send(recognizeTextCommand);
|
|
116
|
+
this._reportBotStatus(data, botConfig);
|
|
117
|
+
return data;
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
return Promise.reject(err);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* handle client's `RecognizeUtteranceCommand`
|
|
125
|
+
* used for obj text or obj voice message
|
|
126
|
+
*/
|
|
127
|
+
async _handleRecognizeUtteranceCommand(botConfig, data, baseParams, client) {
|
|
128
|
+
const { content, options: { messageType }, } = data;
|
|
129
|
+
logger.debug('postContent to lex2', data);
|
|
130
|
+
let params;
|
|
131
|
+
// prepare params
|
|
132
|
+
if (messageType === 'voice') {
|
|
133
|
+
if (typeof content !== 'object') {
|
|
134
|
+
return Promise.reject('invalid content type');
|
|
135
|
+
}
|
|
136
|
+
const inputStream = content instanceof Uint8Array ? content : await (0, utils_2.convert)(content);
|
|
137
|
+
params = {
|
|
138
|
+
...baseParams,
|
|
139
|
+
requestContentType: 'audio/x-l16; sample-rate=16000; channel-count=1',
|
|
140
|
+
inputStream,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// text input
|
|
145
|
+
if (typeof content !== 'string')
|
|
146
|
+
return Promise.reject('invalid content type');
|
|
147
|
+
params = {
|
|
148
|
+
...baseParams,
|
|
149
|
+
requestContentType: 'text/plain; charset=utf-8',
|
|
150
|
+
inputStream: content,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
// make API call to lex
|
|
154
|
+
try {
|
|
155
|
+
const recognizeUtteranceCommand = new client_lex_runtime_v2_1.RecognizeUtteranceCommand(params);
|
|
156
|
+
const data = await client.send(recognizeUtteranceCommand);
|
|
157
|
+
const response = await this._formatUtteranceCommandOutput(data);
|
|
158
|
+
this._reportBotStatus(response, botConfig);
|
|
159
|
+
return response;
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
return Promise.reject(err);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.lexProvider = new AWSLexV2Provider();
|
|
@@ -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 AWSLexV2Provider_1 = require("../AWSLexV2Provider");
|
|
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
|
+
AWSLexV2Provider_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 AWSLexV2Provider_1 = require("../AWSLexV2Provider");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
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 AWSLexV2Provider_1.lexProvider.sendMessage(botConfig, message);
|
|
14
|
+
};
|
|
15
|
+
exports.send = send;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
exports.Interactions = {
|
|
8
|
+
send: apis_1.send,
|
|
9
|
+
onComplete: apis_1.onComplete,
|
|
10
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SendInput, OnCompleteInput } from './inputs';
|
|
2
|
+
import { SendOutput } from './outputs';
|
|
3
|
+
export interface AWSLexV2ProviderOption {
|
|
4
|
+
name: string;
|
|
5
|
+
botId: string;
|
|
6
|
+
aliasId: string;
|
|
7
|
+
localeId: string;
|
|
8
|
+
region: string;
|
|
9
|
+
}
|
|
10
|
+
export interface IInteractions {
|
|
11
|
+
send(input: SendInput): Promise<SendOutput>;
|
|
12
|
+
onComplete(input: OnCompleteInput): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InteractionsSendInput, InteractionsOnCompleteInput } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Input type for LexV2 send API.
|
|
4
|
+
*/
|
|
5
|
+
export type SendInput = InteractionsSendInput;
|
|
6
|
+
/**
|
|
7
|
+
* Input type for LexV2 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?.LexV2 ?? {};
|
|
9
|
+
if (botConfig !== undefined) {
|
|
10
|
+
return { ...botConfig, name: botName };
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
exports.resolveBotConfig = resolveBotConfig;
|