@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.
Files changed (115) hide show
  1. package/lib/errors/InteractionsError.js +7 -11
  2. package/lib/errors/assertValidationError.js +6 -6
  3. package/lib/errors/validation.js +3 -4
  4. package/lib/index.d.ts +1 -1
  5. package/lib/lex-v1/AWSLexProvider.d.ts +2 -2
  6. package/lib/lex-v1/AWSLexProvider.js +90 -124
  7. package/lib/lex-v1/apis/onComplete.d.ts +2 -2
  8. package/lib/lex-v1/apis/onComplete.js +7 -6
  9. package/lib/lex-v1/apis/send.d.ts +2 -2
  10. package/lib/lex-v1/apis/send.js +9 -12
  11. package/lib/lex-v1/index.d.ts +2 -1
  12. package/lib/lex-v1/index.js +1 -1
  13. package/lib/lex-v1/types/AWSLexProviderOption.d.ts +6 -0
  14. package/lib/lex-v1/types/index.d.ts +2 -0
  15. package/lib/lex-v1/types/inputs.d.ts +9 -0
  16. package/lib/lex-v1/types/outputs.d.ts +5 -0
  17. package/lib/lex-v1/types/outputs.js +4 -0
  18. package/lib/lex-v1/utils/resolveBotConfig.js +4 -6
  19. package/lib/lex-v2/AWSLexV2Provider.d.ts +3 -3
  20. package/lib/lex-v2/AWSLexV2Provider.js +115 -174
  21. package/lib/lex-v2/apis/onComplete.d.ts +2 -2
  22. package/lib/lex-v2/apis/onComplete.js +7 -6
  23. package/lib/lex-v2/apis/send.d.ts +2 -2
  24. package/lib/lex-v2/apis/send.js +9 -12
  25. package/lib/lex-v2/index.d.ts +2 -1
  26. package/lib/lex-v2/index.js +1 -1
  27. package/lib/lex-v2/types/AWSLexV2ProviderOption.d.ts +6 -0
  28. package/lib/lex-v2/types/index.d.ts +2 -0
  29. package/lib/lex-v2/types/inputs.d.ts +9 -0
  30. package/lib/lex-v2/types/inputs.js +4 -0
  31. package/lib/lex-v2/types/outputs.d.ts +5 -0
  32. package/lib/lex-v2/types/outputs.js +4 -0
  33. package/lib/lex-v2/utils/resolveBotConfig.js +4 -6
  34. package/lib/tsconfig.tsbuildinfo +1 -1
  35. package/lib/types/Interactions.d.ts +4 -5
  36. package/lib/types/index.d.ts +2 -2
  37. package/lib/types/index.js +2 -0
  38. package/lib/types/inputs.d.ts +9 -0
  39. package/lib/types/inputs.js +4 -0
  40. package/lib/types/outputs.d.ts +2 -0
  41. package/lib/types/outputs.js +4 -0
  42. package/lib/utils/commonUtils.js +13 -24
  43. package/lib/utils/utils.js +22 -31
  44. package/lib/utils/utils.native.js +33 -46
  45. package/lib-esm/errors/InteractionsError.js +6 -11
  46. package/lib-esm/errors/assertValidationError.js +4 -4
  47. package/lib-esm/errors/validation.js +3 -4
  48. package/lib-esm/index.d.ts +1 -1
  49. package/lib-esm/lex-v1/AWSLexProvider.d.ts +2 -2
  50. package/lib-esm/lex-v1/AWSLexProvider.js +87 -121
  51. package/lib-esm/lex-v1/apis/onComplete.d.ts +2 -2
  52. package/lib-esm/lex-v1/apis/onComplete.js +4 -3
  53. package/lib-esm/lex-v1/apis/send.d.ts +2 -2
  54. package/lib-esm/lex-v1/apis/send.js +6 -9
  55. package/lib-esm/lex-v1/index.d.ts +2 -1
  56. package/lib-esm/lex-v1/index.js +3 -3
  57. package/lib-esm/lex-v1/types/AWSLexProviderOption.d.ts +6 -0
  58. package/lib-esm/lex-v1/types/index.d.ts +2 -0
  59. package/lib-esm/lex-v1/types/inputs.d.ts +9 -0
  60. package/lib-esm/lex-v1/types/outputs.d.ts +5 -0
  61. package/lib-esm/lex-v1/types/outputs.js +3 -0
  62. package/lib-esm/lex-v1/utils/resolveBotConfig.js +3 -5
  63. package/lib-esm/lex-v2/AWSLexV2Provider.d.ts +3 -3
  64. package/lib-esm/lex-v2/AWSLexV2Provider.js +111 -170
  65. package/lib-esm/lex-v2/apis/onComplete.d.ts +2 -2
  66. package/lib-esm/lex-v2/apis/onComplete.js +4 -3
  67. package/lib-esm/lex-v2/apis/send.d.ts +2 -2
  68. package/lib-esm/lex-v2/apis/send.js +6 -9
  69. package/lib-esm/lex-v2/index.d.ts +2 -1
  70. package/lib-esm/lex-v2/index.js +3 -3
  71. package/lib-esm/lex-v2/types/AWSLexV2ProviderOption.d.ts +6 -0
  72. package/lib-esm/lex-v2/types/index.d.ts +2 -0
  73. package/lib-esm/lex-v2/types/inputs.d.ts +9 -0
  74. package/lib-esm/lex-v2/types/inputs.js +3 -0
  75. package/lib-esm/lex-v2/types/outputs.d.ts +5 -0
  76. package/lib-esm/lex-v2/types/outputs.js +3 -0
  77. package/lib-esm/lex-v2/utils/resolveBotConfig.js +3 -5
  78. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  79. package/lib-esm/types/Interactions.d.ts +4 -5
  80. package/lib-esm/types/index.d.ts +2 -2
  81. package/lib-esm/types/index.js +2 -0
  82. package/lib-esm/types/inputs.d.ts +9 -0
  83. package/lib-esm/types/inputs.js +3 -0
  84. package/lib-esm/types/outputs.d.ts +2 -0
  85. package/lib-esm/types/outputs.js +3 -0
  86. package/lib-esm/utils/commonUtils.js +12 -23
  87. package/lib-esm/utils/utils.js +21 -30
  88. package/lib-esm/utils/utils.native.js +31 -44
  89. package/package.json +4 -7
  90. package/src/index.ts +1 -7
  91. package/src/lex-v1/AWSLexProvider.ts +10 -5
  92. package/src/lex-v1/apis/onComplete.ts +3 -5
  93. package/src/lex-v1/apis/send.ts +3 -5
  94. package/src/lex-v1/index.ts +2 -1
  95. package/src/lex-v1/types/AWSLexProviderOption.ts +8 -0
  96. package/src/lex-v1/types/index.ts +2 -0
  97. package/src/lex-v1/types/inputs.ts +17 -0
  98. package/src/lex-v1/types/outputs.ts +9 -0
  99. package/src/lex-v2/AWSLexV2Provider.ts +8 -6
  100. package/src/lex-v2/apis/onComplete.ts +3 -5
  101. package/src/lex-v2/apis/send.ts +3 -5
  102. package/src/lex-v2/index.ts +2 -1
  103. package/src/lex-v2/types/AWSLexV2ProviderOption.ts +8 -0
  104. package/src/lex-v2/types/index.ts +2 -0
  105. package/src/lex-v2/types/inputs.ts +17 -0
  106. package/src/lex-v2/types/outputs.ts +9 -0
  107. package/src/types/Interactions.ts +8 -9
  108. package/src/types/index.ts +3 -6
  109. package/src/types/inputs.ts +17 -0
  110. package/src/types/outputs.ts +6 -0
  111. package/lib/types/Response.d.ts +0 -4
  112. package/lib-esm/types/Response.d.ts +0 -4
  113. package/src/types/Response.ts +0 -11
  114. /package/lib/{types/Response.js → lex-v1/types/inputs.js} +0 -0
  115. /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
- var tslib_1 = require("tslib");
7
- var utils_1 = require("@aws-amplify/core/internals/utils");
8
- var InteractionsError = /** @class */ (function (_super) {
9
- tslib_1.__extends(InteractionsError, _super);
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
- _this.constructor = InteractionsError;
15
- Object.setPrototypeOf(_this, InteractionsError.prototype);
16
- return _this;
12
+ this.constructor = InteractionsError;
13
+ Object.setPrototypeOf(this, InteractionsError.prototype);
17
14
  }
18
- return InteractionsError;
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
- var validation_1 = require("./validation");
7
- var InteractionsError_1 = require("./InteractionsError");
6
+ const validation_1 = require("./validation");
7
+ const InteractionsError_1 = require("./InteractionsError");
8
8
  function assertValidationError(assertion, name, message) {
9
9
  if (!assertion) {
10
- var _a = validation_1.validationErrorMap[name], defaultMessage = _a.message, recoverySuggestion = _a.recoverySuggestion;
10
+ const { message: defaultMessage, recoverySuggestion } = validation_1.validationErrorMap[name];
11
11
  throw new InteractionsError_1.InteractionsError({
12
- name: name,
13
- message: message !== null && message !== void 0 ? message : defaultMessage,
14
- recoverySuggestion: recoverySuggestion,
12
+ name,
13
+ message: message ?? defaultMessage,
14
+ recoverySuggestion,
15
15
  });
16
16
  }
17
17
  }
@@ -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 = (_a = {},
12
- _a[InteractionsValidationErrorCode.NoBotConfig] = {
10
+ exports.validationErrorMap = {
11
+ [InteractionsValidationErrorCode.NoBotConfig]: {
13
12
  message: 'Missing configuration for the bot',
14
13
  },
15
- _a);
14
+ };
package/lib/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { InteractionsMessage, InteractionsResponse, InteractionsVoiceMessage, InteractionsTextMessage, CompletionCallback, } from './types';
2
1
  export { Interactions } from './lex-v2';
2
+ export { SendInput, OnCompleteInput, SendOutput } from './lex-v2/types';
@@ -1,4 +1,4 @@
1
- import { CompletionCallback, InteractionsMessage, InteractionsResponse } from '../types';
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: CompletionCallback): void;
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
- var tslib_1 = require("tslib");
5
- var client_lex_runtime_service_1 = require("@aws-sdk/client-lex-runtime-service");
6
- var utils_1 = require("@aws-amplify/core/internals/utils");
7
- var core_1 = require("@aws-amplify/core");
8
- var utils_2 = require("../utils");
9
- var logger = new core_1.ConsoleLogger('AWSLexProvider');
10
- var AWSLexProvider = /** @class */ (function () {
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
- AWSLexProvider.prototype.reportBotStatus = function (data, _a) {
20
- var name = _a.name;
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
- AWSLexProvider.prototype.sendMessage = function (botConfig, message) {
40
- return tslib_1.__awaiter(this, void 0, void 0, function () {
41
- var session, error_1, name, region, alias, client, params, postTextCommand, data, err_1, content, messageType, inputStream, _a, postContentCommand, data, audioArray, _b, response, err_2;
42
- return tslib_1.__generator(this, function (_c) {
43
- switch (_c.label) {
44
- case 0:
45
- _c.trys.push([0, 2, , 3]);
46
- return [4 /*yield*/, (0, core_1.fetchAuthSession)()];
47
- case 1:
48
- session = _c.sent();
49
- return [3 /*break*/, 3];
50
- case 2:
51
- error_1 = _c.sent();
52
- return [2 /*return*/, Promise.reject('No credentials')];
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
- AWSLexProvider.prototype.onComplete = function (_a, callback) {
148
- var name = _a.name;
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
- return AWSLexProvider;
152
- }());
117
+ }
118
+ }
153
119
  exports.lexProvider = new AWSLexProvider();
@@ -1,2 +1,2 @@
1
- import { CompletionCallback } from '../../types';
2
- export declare const onComplete: (botName: string, callback: CompletionCallback) => void;
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
- var utils_1 = require("../utils");
7
- var AWSLexProvider_1 = require("../AWSLexProvider");
8
- var errors_1 = require("../../errors");
9
- var onComplete = function (botName, callback) {
10
- var botConfig = (0, utils_1.resolveBotConfig)(botName);
11
- (0, errors_1.assertValidationError)(!!botConfig, errors_1.InteractionsValidationErrorCode.NoBotConfig, "Bot ".concat(botName, " does not exist."));
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 { InteractionsMessage, InteractionsResponse } from '../../types';
2
- export declare const send: (botName: string, message: string | InteractionsMessage) => Promise<InteractionsResponse>;
1
+ import { SendInput, SendOutput } from '../types';
2
+ export declare const send: (input: SendInput) => Promise<SendOutput>;
@@ -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
- var tslib_1 = require("tslib");
7
- var utils_1 = require("../utils");
8
- var AWSLexProvider_1 = require("../AWSLexProvider");
9
- var errors_1 = require("../../errors");
10
- var send = function (botName, message) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
11
- var botConfig;
12
- return tslib_1.__generator(this, function (_a) {
13
- botConfig = (0, utils_1.resolveBotConfig)(botName);
14
- (0, errors_1.assertValidationError)(!!botConfig, errors_1.InteractionsValidationErrorCode.NoBotConfig, "Bot ".concat(botName, " does not exist."));
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;
@@ -1,5 +1,6 @@
1
- import { IInteractions } from '../types/Interactions';
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';
@@ -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
- var apis_1 = require("./apis");
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
+ }
@@ -1 +1,3 @@
1
1
  export { AWSLexProviderOption } from './AWSLexProviderOption';
2
+ export { SendInput, OnCompleteInput } from './inputs';
3
+ export { SendOutput } from './outputs';
@@ -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,5 @@
1
+ import { InteractionsSendOutput } from '../../types';
2
+ /**
3
+ * Output type for LexV1 send API.
4
+ */
5
+ export type SendOutput = InteractionsSendOutput;
@@ -0,0 +1,4 @@
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 });
@@ -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
- var tslib_1 = require("tslib");
7
- var core_1 = require("@aws-amplify/core");
8
- var resolveBotConfig = function (botName) {
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 tslib_1.__assign(tslib_1.__assign({}, botConfig), { name: botName });
10
+ return { ...botConfig, name: botName };
13
11
  }
14
12
  };
15
13
  exports.resolveBotConfig = resolveBotConfig;
@@ -1,4 +1,4 @@
1
- import { CompletionCallback, InteractionsMessage, InteractionsResponse } from '../types';
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 {CompletionCallback} callback - called when Intent Fulfilled
27
+ * @param {InteractionsOnCompleteCallback} callback - called when Intent Fulfilled
28
28
  */
29
- onComplete({ name }: AWSLexV2ProviderOption, callback: CompletionCallback): void;
29
+ onComplete({ name }: AWSLexV2ProviderOption, callback: InteractionsOnCompleteCallback): void;
30
30
  /**
31
31
  * call onComplete callback for a bot if configured
32
32
  */