@aws-amplify/interactions 6.0.22 → 6.0.23
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/dist/cjs/lex-v1/AWSLexProvider.js +5 -3
- package/dist/cjs/lex-v1/AWSLexProvider.js.map +1 -1
- package/dist/cjs/lex-v2/AWSLexV2Provider.js +11 -9
- package/dist/cjs/lex-v2/AWSLexV2Provider.js.map +1 -1
- package/dist/cjs/utils/commonUtils.js +1 -1
- package/dist/cjs/utils/commonUtils.js.map +1 -1
- package/dist/cjs/utils/utils.js +2 -2
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/cjs/utils/utils.native.js +4 -4
- package/dist/cjs/utils/utils.native.js.map +1 -1
- package/dist/esm/lex-v1/AWSLexProvider.d.ts +1 -1
- package/dist/esm/lex-v1/AWSLexProvider.mjs +5 -3
- package/dist/esm/lex-v1/AWSLexProvider.mjs.map +1 -1
- package/dist/esm/lex-v1/apis/onComplete.mjs.map +1 -1
- package/dist/esm/lex-v1/apis/send.mjs.map +1 -1
- package/dist/esm/lex-v1/index.mjs.map +1 -1
- package/dist/esm/lex-v1/types/AWSLexProviderOption.d.ts +1 -1
- package/dist/esm/lex-v1/types/inputs.d.ts +1 -1
- package/dist/esm/lex-v2/AWSLexV2Provider.d.ts +1 -1
- package/dist/esm/lex-v2/AWSLexV2Provider.mjs +11 -9
- package/dist/esm/lex-v2/AWSLexV2Provider.mjs.map +1 -1
- package/dist/esm/lex-v2/apis/onComplete.mjs.map +1 -1
- package/dist/esm/lex-v2/apis/send.mjs.map +1 -1
- package/dist/esm/lex-v2/index.mjs.map +1 -1
- package/dist/esm/lex-v2/types/AWSLexV2ProviderOption.d.ts +1 -1
- package/dist/esm/lex-v2/types/inputs.d.ts +1 -1
- package/dist/esm/types/Interactions.d.ts +5 -7
- package/dist/esm/types/inputs.d.ts +4 -4
- package/dist/esm/utils/commonUtils.mjs +1 -1
- package/dist/esm/utils/commonUtils.mjs.map +1 -1
- package/dist/esm/utils/utils.mjs +2 -2
- package/dist/esm/utils/utils.mjs.map +1 -1
- package/dist/esm/utils/utils.native.mjs +4 -4
- package/dist/esm/utils/utils.native.mjs.map +1 -1
- package/package.json +5 -4
- package/src/lex-v1/AWSLexProvider.ts +12 -8
- package/src/lex-v1/apis/onComplete.ts +1 -1
- package/src/lex-v1/apis/send.ts +2 -1
- package/src/lex-v1/index.ts +1 -1
- package/src/lex-v1/types/AWSLexProviderOption.ts +1 -1
- package/src/lex-v1/types/inputs.ts +1 -1
- package/src/lex-v1/utils/resolveBotConfig.ts +2 -1
- package/src/lex-v2/AWSLexV2Provider.ts +22 -16
- package/src/lex-v2/apis/onComplete.ts +1 -1
- package/src/lex-v2/apis/send.ts +2 -1
- package/src/lex-v2/index.ts +1 -1
- package/src/lex-v2/types/AWSLexV2ProviderOption.ts +1 -1
- package/src/lex-v2/types/inputs.ts +1 -1
- package/src/lex-v2/utils/resolveBotConfig.ts +2 -1
- package/src/types/Interactions.ts +5 -7
- package/src/types/inputs.ts +4 -4
- package/src/utils/commonUtils.ts +3 -1
- package/src/utils/utils.native.ts +5 -4
- package/src/utils/utils.ts +2 -2
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface InteractionsTextMessage {
|
|
2
2
|
content: string;
|
|
3
3
|
options: {
|
|
4
4
|
messageType: 'text';
|
|
5
5
|
};
|
|
6
|
-
}
|
|
7
|
-
export
|
|
6
|
+
}
|
|
7
|
+
export interface InteractionsVoiceMessage {
|
|
8
8
|
content: object;
|
|
9
9
|
options: {
|
|
10
10
|
messageType: 'voice';
|
|
11
11
|
};
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
13
|
export type InteractionsMessage = InteractionsTextMessage | InteractionsVoiceMessage;
|
|
14
14
|
export type InteractionsOnCompleteCallback = (error?: Error, completion?: InteractionsResponse) => void;
|
|
15
|
-
export type InteractionsResponse =
|
|
16
|
-
[key: string]: any;
|
|
17
|
-
};
|
|
15
|
+
export type InteractionsResponse = Record<string, any>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { InteractionsMessage, InteractionsOnCompleteCallback } from './Interactions';
|
|
2
|
-
export
|
|
2
|
+
export interface InteractionsSendInput {
|
|
3
3
|
botName: string;
|
|
4
4
|
message: string | InteractionsMessage;
|
|
5
|
-
}
|
|
6
|
-
export
|
|
5
|
+
}
|
|
6
|
+
export interface InteractionsOnCompleteInput {
|
|
7
7
|
botName: string;
|
|
8
8
|
callback: InteractionsOnCompleteCallback;
|
|
9
|
-
}
|
|
9
|
+
}
|
|
@@ -11,7 +11,7 @@ const unGzipBase64AsJson = async (gzipBase64) => {
|
|
|
11
11
|
return JSON.parse(objString);
|
|
12
12
|
}
|
|
13
13
|
catch (error) {
|
|
14
|
-
return Promise.reject('unable to decode and decompress ' + error);
|
|
14
|
+
return Promise.reject(new Error('unable to decode and decompress ' + error));
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commonUtils.mjs","sources":["../../../src/utils/commonUtils.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { base64ToArrayBuffer, gzipDecompressToString } from './utils';\nexport const unGzipBase64AsJson = async (gzipBase64) => {\n if (typeof gzipBase64 === 'undefined')\n return undefined;\n try {\n const decodedArrayBuffer = base64ToArrayBuffer(gzipBase64);\n const objString = await gzipDecompressToString(decodedArrayBuffer);\n return JSON.parse(objString);\n }\n catch (error) {\n return Promise.reject('unable to decode and decompress ' + error);\n }\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,kBAAkB,GAAG,OAAO,UAAU,KAAK;AACxD,IAAI,IAAI,OAAO,UAAU,KAAK,WAAW;AACzC,QAAQ,OAAO,SAAS,CAAC;AACzB,IAAI,IAAI;AACR,QAAQ,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;AACnE,QAAQ,MAAM,SAAS,GAAG,MAAM,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;AAC3E,QAAQ,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACrC,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,kCAAkC,GAAG,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"commonUtils.mjs","sources":["../../../src/utils/commonUtils.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { base64ToArrayBuffer, gzipDecompressToString } from './utils';\nexport const unGzipBase64AsJson = async (gzipBase64) => {\n if (typeof gzipBase64 === 'undefined')\n return undefined;\n try {\n const decodedArrayBuffer = base64ToArrayBuffer(gzipBase64);\n const objString = await gzipDecompressToString(decodedArrayBuffer);\n return JSON.parse(objString);\n }\n catch (error) {\n return Promise.reject(new Error('unable to decode and decompress ' + error));\n }\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,kBAAkB,GAAG,OAAO,UAAU,KAAK;AACxD,IAAI,IAAI,OAAO,UAAU,KAAK,WAAW;AACzC,QAAQ,OAAO,SAAS,CAAC;AACzB,IAAI,IAAI;AACR,QAAQ,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;AACnE,QAAQ,MAAM,SAAS,GAAG,MAAM,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;AAC3E,QAAQ,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACrC,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,kCAAkC,GAAG,KAAK,CAAC,CAAC,CAAC;AACrF,KAAK;AACL;;;;"}
|
package/dist/esm/utils/utils.mjs
CHANGED
|
@@ -9,14 +9,14 @@ const convert = async (stream) => {
|
|
|
9
9
|
.then(buffer => new Uint8Array(buffer));
|
|
10
10
|
}
|
|
11
11
|
else {
|
|
12
|
-
return Promise.reject('Invalid content type');
|
|
12
|
+
return Promise.reject(new Error('Invalid content type'));
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
const base64ToArrayBuffer = (base64) => {
|
|
16
16
|
return Uint8Array.from(window.atob(base64), c => c.charCodeAt(0));
|
|
17
17
|
};
|
|
18
18
|
const gzipDecompressToString = async (data) => {
|
|
19
|
-
return
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
20
|
gunzip(data, (err, resp) => {
|
|
21
21
|
if (err)
|
|
22
22
|
reject(err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../src/utils/utils.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { gunzip, strFromU8 } from 'fflate';\nexport const convert = async (stream) => {\n if (stream instanceof Blob || stream instanceof ReadableStream) {\n return new Response(stream)\n .arrayBuffer()\n .then(buffer => new Uint8Array(buffer));\n }\n else {\n return Promise.reject('Invalid content type');\n }\n};\nexport const base64ToArrayBuffer = (base64) => {\n return Uint8Array.from(window.atob(base64), c => c.charCodeAt(0));\n};\nexport const gzipDecompressToString = async (data) => {\n return
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../src/utils/utils.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { gunzip, strFromU8 } from 'fflate';\nexport const convert = async (stream) => {\n if (stream instanceof Blob || stream instanceof ReadableStream) {\n return new Response(stream)\n .arrayBuffer()\n .then(buffer => new Uint8Array(buffer));\n }\n else {\n return Promise.reject(new Error('Invalid content type'));\n }\n};\nexport const base64ToArrayBuffer = (base64) => {\n return Uint8Array.from(window.atob(base64), c => c.charCodeAt(0));\n};\nexport const gzipDecompressToString = async (data) => {\n return new Promise((resolve, reject) => {\n gunzip(data, (err, resp) => {\n if (err)\n reject(err);\n else\n resolve(strFromU8(resp));\n });\n });\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,OAAO,GAAG,OAAO,MAAM,KAAK;AACzC,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,MAAM,YAAY,cAAc,EAAE;AACpE,QAAQ,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC;AACnC,aAAa,WAAW,EAAE;AAC1B,aAAa,IAAI,CAAC,MAAM,IAAI,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AACpD,KAAK;AACL,SAAS;AACT,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC;AACjE,KAAK;AACL,EAAE;AACU,MAAC,mBAAmB,GAAG,CAAC,MAAM,KAAK;AAC/C,IAAI,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AACtE,EAAE;AACU,MAAC,sBAAsB,GAAG,OAAO,IAAI,KAAK;AACtD,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAC5C,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK;AACpC,YAAY,IAAI,GAAG;AACnB,gBAAgB,MAAM,CAAC,GAAG,CAAC,CAAC;AAC5B;AACA,gBAAgB,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AACzC,SAAS,CAAC,CAAC;AACX,KAAK,CAAC,CAAC;AACP;;;;"}
|
|
@@ -5,9 +5,9 @@ import { ungzip } from 'pako';
|
|
|
5
5
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
6
|
const convert = async (stream) => {
|
|
7
7
|
if (!(stream instanceof Blob)) {
|
|
8
|
-
return Promise.reject('Invalid content type');
|
|
8
|
+
return Promise.reject(new Error('Invalid content type'));
|
|
9
9
|
}
|
|
10
|
-
return new Promise(
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
11
|
try {
|
|
12
12
|
const fileReaderInstance = new FileReader();
|
|
13
13
|
fileReaderInstance.readAsDataURL(stream);
|
|
@@ -19,7 +19,7 @@ const convert = async (stream) => {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
catch (error) {
|
|
22
|
-
reject('unable to convert blob to arrayBuffer: ' + error);
|
|
22
|
+
reject(new Error('unable to convert blob to arrayBuffer: ' + error));
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
};
|
|
@@ -34,7 +34,7 @@ const gzipDecompressToString = async (data) => {
|
|
|
34
34
|
resolve(result);
|
|
35
35
|
}
|
|
36
36
|
catch (error) {
|
|
37
|
-
reject('unable to decompress' + error);
|
|
37
|
+
reject(new Error('unable to decompress' + error));
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.native.mjs","sources":["../../../src/utils/utils.native.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { decode } from 'base-64';\nimport { ungzip } from 'pako';\nexport const convert = async (stream) => {\n if (!(stream instanceof Blob)) {\n return Promise.reject('Invalid content type');\n }\n return new Promise(
|
|
1
|
+
{"version":3,"file":"utils.native.mjs","sources":["../../../src/utils/utils.native.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { decode } from 'base-64';\nimport { ungzip } from 'pako';\nexport const convert = async (stream) => {\n if (!(stream instanceof Blob)) {\n return Promise.reject(new Error('Invalid content type'));\n }\n return new Promise((resolve, reject) => {\n try {\n const fileReaderInstance = new FileReader();\n fileReaderInstance.readAsDataURL(stream);\n fileReaderInstance.onload = async () => {\n const blobURL = fileReaderInstance.result;\n const base64Blob = blobURL.split(/,(.*)/s)[1];\n const decodedArrayBuffer = base64ToArrayBuffer(base64Blob);\n resolve(decodedArrayBuffer);\n };\n }\n catch (error) {\n reject(new Error('unable to convert blob to arrayBuffer: ' + error));\n }\n });\n};\nexport const base64ToArrayBuffer = (base64) => {\n const binaryString = decode(base64);\n return Uint8Array.from(binaryString, c => c.charCodeAt(0));\n};\nexport const gzipDecompressToString = async (data) => {\n return new Promise((resolve, reject) => {\n try {\n const result = ungzip(data, { to: 'string' });\n resolve(result);\n }\n catch (error) {\n reject(new Error('unable to decompress' + error));\n }\n });\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAGY,MAAC,OAAO,GAAG,OAAO,MAAM,KAAK;AACzC,IAAI,IAAI,EAAE,MAAM,YAAY,IAAI,CAAC,EAAE;AACnC,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC;AACjE,KAAK;AACL,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAC5C,QAAQ,IAAI;AACZ,YAAY,MAAM,kBAAkB,GAAG,IAAI,UAAU,EAAE,CAAC;AACxD,YAAY,kBAAkB,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;AACrD,YAAY,kBAAkB,CAAC,MAAM,GAAG,YAAY;AACpD,gBAAgB,MAAM,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAC1D,gBAAgB,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9D,gBAAgB,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAC3E,gBAAgB,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC5C,aAAa,CAAC;AACd,SAAS;AACT,QAAQ,OAAO,KAAK,EAAE;AACtB,YAAY,MAAM,CAAC,IAAI,KAAK,CAAC,yCAAyC,GAAG,KAAK,CAAC,CAAC,CAAC;AACjF,SAAS;AACT,KAAK,CAAC,CAAC;AACP,EAAE;AACU,MAAC,mBAAmB,GAAG,CAAC,MAAM,KAAK;AAC/C,IAAI,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AACxC,IAAI,OAAO,UAAU,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/D,EAAE;AACU,MAAC,sBAAsB,GAAG,OAAO,IAAI,KAAK;AACtD,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAC5C,QAAQ,IAAI;AACZ,YAAY,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC1D,YAAY,OAAO,CAAC,MAAM,CAAC,CAAC;AAC5B,SAAS;AACT,QAAQ,OAAO,KAAK,EAAE;AACtB,YAAY,MAAM,CAAC,IAAI,KAAK,CAAC,sBAAsB,GAAG,KAAK,CAAC,CAAC,CAAC;AAC9D,SAAS;AACT,KAAK,CAAC,CAAC;AACP;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/interactions",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.23",
|
|
4
4
|
"description": "Interactions category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"clean": "npm run clean:size && rimraf dist lib lib-esm",
|
|
22
22
|
"clean:size": "rimraf dual-publish-tmp tmp*",
|
|
23
23
|
"format": "echo \"Not implemented\"",
|
|
24
|
-
"lint": "
|
|
24
|
+
"lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
|
|
25
|
+
"lint:fix": "eslint '**/*.{ts,tsx}' --fix",
|
|
25
26
|
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 88.6"
|
|
26
27
|
},
|
|
27
28
|
"typesVersions": {
|
|
@@ -80,7 +81,7 @@
|
|
|
80
81
|
"uuid": "^9.0.0"
|
|
81
82
|
},
|
|
82
83
|
"devDependencies": {
|
|
83
|
-
"@aws-amplify/core": "6.0.
|
|
84
|
+
"@aws-amplify/core": "6.0.23",
|
|
84
85
|
"typescript": "^5.0.2"
|
|
85
86
|
},
|
|
86
87
|
"size-limit": [
|
|
@@ -103,5 +104,5 @@
|
|
|
103
104
|
"limit": "47.00 kB"
|
|
104
105
|
}
|
|
105
106
|
],
|
|
106
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "6c46368559f4c3229024d10c18aabb34c58efe68"
|
|
107
108
|
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
InteractionsOnCompleteCallback,
|
|
5
|
-
InteractionsMessage,
|
|
6
|
-
InteractionsResponse,
|
|
7
|
-
} from '../types/Interactions';
|
|
8
3
|
import {
|
|
9
4
|
DialogState,
|
|
10
5
|
LexRuntimeServiceClient,
|
|
@@ -17,7 +12,14 @@ import {
|
|
|
17
12
|
} from '@aws-sdk/client-lex-runtime-service';
|
|
18
13
|
import { getAmplifyUserAgentObject } from '@aws-amplify/core/internals/utils';
|
|
19
14
|
import { ConsoleLogger, fetchAuthSession } from '@aws-amplify/core';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
InteractionsMessage,
|
|
18
|
+
InteractionsOnCompleteCallback,
|
|
19
|
+
InteractionsResponse,
|
|
20
|
+
} from '../types/Interactions';
|
|
20
21
|
import { convert } from '../utils';
|
|
22
|
+
|
|
21
23
|
import { AWSLexProviderOption } from './types';
|
|
22
24
|
|
|
23
25
|
const logger = new ConsoleLogger('AWSLexProvider');
|
|
@@ -75,7 +77,7 @@ class AWSLexProvider {
|
|
|
75
77
|
try {
|
|
76
78
|
session = await fetchAuthSession();
|
|
77
79
|
} catch (error) {
|
|
78
|
-
return Promise.reject('No credentials');
|
|
80
|
+
return Promise.reject(new Error('No credentials'));
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
const { name, region, alias } = botConfig;
|
|
@@ -100,6 +102,7 @@ class AWSLexProvider {
|
|
|
100
102
|
const data = await client.send(postTextCommand);
|
|
101
103
|
|
|
102
104
|
this.reportBotStatus(data, botConfig);
|
|
105
|
+
|
|
103
106
|
return data;
|
|
104
107
|
} catch (err) {
|
|
105
108
|
return Promise.reject(err);
|
|
@@ -111,7 +114,7 @@ class AWSLexProvider {
|
|
|
111
114
|
} = message;
|
|
112
115
|
if (messageType === 'voice') {
|
|
113
116
|
if (typeof content !== 'object') {
|
|
114
|
-
return Promise.reject('invalid content type');
|
|
117
|
+
return Promise.reject(new Error('invalid content type'));
|
|
115
118
|
}
|
|
116
119
|
const inputStream =
|
|
117
120
|
content instanceof Uint8Array ? content : await convert(content);
|
|
@@ -126,7 +129,7 @@ class AWSLexProvider {
|
|
|
126
129
|
};
|
|
127
130
|
} else {
|
|
128
131
|
if (typeof content !== 'string')
|
|
129
|
-
return Promise.reject('invalid content type');
|
|
132
|
+
return Promise.reject(new Error('invalid content type'));
|
|
130
133
|
|
|
131
134
|
params = {
|
|
132
135
|
botAlias: alias,
|
|
@@ -149,6 +152,7 @@ class AWSLexProvider {
|
|
|
149
152
|
const response = { ...data, ...{ audioStream: audioArray } };
|
|
150
153
|
|
|
151
154
|
this.reportBotStatus(response, botConfig);
|
|
155
|
+
|
|
152
156
|
return response;
|
|
153
157
|
} catch (err) {
|
|
154
158
|
return Promise.reject(err);
|
|
@@ -5,8 +5,8 @@ import { OnCompleteInput } from '../types';
|
|
|
5
5
|
import { resolveBotConfig } from '../utils';
|
|
6
6
|
import { lexProvider } from '../AWSLexProvider';
|
|
7
7
|
import {
|
|
8
|
-
assertValidationError,
|
|
9
8
|
InteractionsValidationErrorCode,
|
|
9
|
+
assertValidationError,
|
|
10
10
|
} from '../../errors';
|
|
11
11
|
|
|
12
12
|
export const onComplete = (input: OnCompleteInput): void => {
|
package/src/lex-v1/apis/send.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { SendInput, SendOutput } from '../types';
|
|
|
5
5
|
import { resolveBotConfig } from '../utils';
|
|
6
6
|
import { lexProvider } from '../AWSLexProvider';
|
|
7
7
|
import {
|
|
8
|
-
assertValidationError,
|
|
9
8
|
InteractionsValidationErrorCode,
|
|
9
|
+
assertValidationError,
|
|
10
10
|
} from '../../errors';
|
|
11
11
|
|
|
12
12
|
export const send = async (input: SendInput): Promise<SendOutput> => {
|
|
@@ -17,5 +17,6 @@ export const send = async (input: SendInput): Promise<SendOutput> => {
|
|
|
17
17
|
InteractionsValidationErrorCode.NoBotConfig,
|
|
18
18
|
`Bot ${botName} does not exist.`,
|
|
19
19
|
);
|
|
20
|
+
|
|
20
21
|
return lexProvider.sendMessage(botConfig, message);
|
|
21
22
|
};
|
package/src/lex-v1/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { onComplete, send } from './apis';
|
|
5
5
|
import { IInteractions } from './types/AWSLexProviderOption';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { OnCompleteInput, SendInput } from './inputs';
|
|
5
5
|
import { SendOutput } from './outputs';
|
|
6
6
|
|
|
7
7
|
export interface AWSLexProviderOption {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { AWSLexProviderOption } from '../types';
|
|
5
4
|
import { Amplify } from '@aws-amplify/core';
|
|
6
5
|
|
|
6
|
+
import { AWSLexProviderOption } from '../types';
|
|
7
|
+
|
|
7
8
|
export const resolveBotConfig = (
|
|
8
9
|
botName: string,
|
|
9
10
|
): AWSLexProviderOption | undefined => {
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
InteractionsOnCompleteCallback,
|
|
5
|
-
InteractionsMessage,
|
|
6
|
-
InteractionsResponse,
|
|
7
|
-
} from '../types/Interactions';
|
|
8
3
|
import {
|
|
9
4
|
IntentState,
|
|
10
5
|
LexRuntimeV2Client,
|
|
@@ -17,8 +12,15 @@ import {
|
|
|
17
12
|
} from '@aws-sdk/client-lex-runtime-v2';
|
|
18
13
|
import { getAmplifyUserAgentObject } from '@aws-amplify/core/internals/utils';
|
|
19
14
|
import { ConsoleLogger, fetchAuthSession } from '@aws-amplify/core';
|
|
20
|
-
import { convert, unGzipBase64AsJson } from '../utils';
|
|
21
15
|
import { v4 as uuid } from 'uuid';
|
|
16
|
+
|
|
17
|
+
import { convert, unGzipBase64AsJson } from '../utils';
|
|
18
|
+
import {
|
|
19
|
+
InteractionsMessage,
|
|
20
|
+
InteractionsOnCompleteCallback,
|
|
21
|
+
InteractionsResponse,
|
|
22
|
+
} from '../types/Interactions';
|
|
23
|
+
|
|
22
24
|
import { AWSLexV2ProviderOption } from './types';
|
|
23
25
|
|
|
24
26
|
const logger = new ConsoleLogger('AWSLexV2Provider');
|
|
@@ -43,18 +45,19 @@ type AWSLexV2ProviderSendResponse =
|
|
|
43
45
|
| RecognizeTextCommandOutput
|
|
44
46
|
| RecognizeUtteranceCommandOutputFormatted;
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
interface lexV2BaseReqParams {
|
|
47
49
|
botId: string;
|
|
48
50
|
botAliasId: string;
|
|
49
51
|
localeId: string;
|
|
50
52
|
sessionId: string;
|
|
51
|
-
}
|
|
53
|
+
}
|
|
52
54
|
|
|
53
55
|
class AWSLexV2Provider {
|
|
54
56
|
private readonly _botsCompleteCallback: Record<
|
|
55
57
|
string,
|
|
56
58
|
InteractionsOnCompleteCallback
|
|
57
59
|
> = {};
|
|
60
|
+
|
|
58
61
|
private defaultSessionId: string = uuid();
|
|
59
62
|
|
|
60
63
|
/**
|
|
@@ -73,7 +76,7 @@ class AWSLexV2Provider {
|
|
|
73
76
|
try {
|
|
74
77
|
session = await fetchAuthSession();
|
|
75
78
|
} catch (error) {
|
|
76
|
-
return Promise.reject('No credentials');
|
|
79
|
+
return Promise.reject(new Error('No credentials'));
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
const { region, aliasId, localeId, botId } = botConfig;
|
|
@@ -108,6 +111,7 @@ class AWSLexV2Provider {
|
|
|
108
111
|
client,
|
|
109
112
|
);
|
|
110
113
|
}
|
|
114
|
+
|
|
111
115
|
return response;
|
|
112
116
|
}
|
|
113
117
|
|
|
@@ -193,10 +197,11 @@ class AWSLexV2Provider {
|
|
|
193
197
|
|
|
194
198
|
try {
|
|
195
199
|
const recognizeTextCommand = new RecognizeTextCommand(params);
|
|
196
|
-
const
|
|
200
|
+
const resultData = await client.send(recognizeTextCommand);
|
|
197
201
|
|
|
198
|
-
this._reportBotStatus(
|
|
199
|
-
|
|
202
|
+
this._reportBotStatus(resultData, botConfig);
|
|
203
|
+
|
|
204
|
+
return resultData;
|
|
200
205
|
} catch (err) {
|
|
201
206
|
return Promise.reject(err);
|
|
202
207
|
}
|
|
@@ -223,7 +228,7 @@ class AWSLexV2Provider {
|
|
|
223
228
|
// prepare params
|
|
224
229
|
if (messageType === 'voice') {
|
|
225
230
|
if (typeof content !== 'object') {
|
|
226
|
-
return Promise.reject('invalid content type');
|
|
231
|
+
return Promise.reject(new Error('invalid content type'));
|
|
227
232
|
}
|
|
228
233
|
|
|
229
234
|
const inputStream =
|
|
@@ -237,7 +242,7 @@ class AWSLexV2Provider {
|
|
|
237
242
|
} else {
|
|
238
243
|
// text input
|
|
239
244
|
if (typeof content !== 'string')
|
|
240
|
-
return Promise.reject('invalid content type');
|
|
245
|
+
return Promise.reject(new Error('invalid content type'));
|
|
241
246
|
|
|
242
247
|
params = {
|
|
243
248
|
...baseParams,
|
|
@@ -249,10 +254,11 @@ class AWSLexV2Provider {
|
|
|
249
254
|
// make API call to lex
|
|
250
255
|
try {
|
|
251
256
|
const recognizeUtteranceCommand = new RecognizeUtteranceCommand(params);
|
|
252
|
-
const
|
|
257
|
+
const resultData = await client.send(recognizeUtteranceCommand);
|
|
253
258
|
|
|
254
|
-
const response = await this._formatUtteranceCommandOutput(
|
|
259
|
+
const response = await this._formatUtteranceCommandOutput(resultData);
|
|
255
260
|
this._reportBotStatus(response, botConfig);
|
|
261
|
+
|
|
256
262
|
return response;
|
|
257
263
|
} catch (err) {
|
|
258
264
|
return Promise.reject(err);
|
|
@@ -5,8 +5,8 @@ import { OnCompleteInput } from '../types';
|
|
|
5
5
|
import { resolveBotConfig } from '../utils';
|
|
6
6
|
import { lexProvider } from '../AWSLexV2Provider';
|
|
7
7
|
import {
|
|
8
|
-
assertValidationError,
|
|
9
8
|
InteractionsValidationErrorCode,
|
|
9
|
+
assertValidationError,
|
|
10
10
|
} from '../../errors';
|
|
11
11
|
|
|
12
12
|
export const onComplete = (input: OnCompleteInput): void => {
|
package/src/lex-v2/apis/send.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { SendInput, SendOutput } from '../types';
|
|
|
5
5
|
import { lexProvider } from '../AWSLexV2Provider';
|
|
6
6
|
import { resolveBotConfig } from '../utils';
|
|
7
7
|
import {
|
|
8
|
-
assertValidationError,
|
|
9
8
|
InteractionsValidationErrorCode,
|
|
9
|
+
assertValidationError,
|
|
10
10
|
} from '../../errors';
|
|
11
11
|
|
|
12
12
|
export const send = async (input: SendInput): Promise<SendOutput> => {
|
|
@@ -17,5 +17,6 @@ export const send = async (input: SendInput): Promise<SendOutput> => {
|
|
|
17
17
|
InteractionsValidationErrorCode.NoBotConfig,
|
|
18
18
|
`Bot ${botName} does not exist.`,
|
|
19
19
|
);
|
|
20
|
+
|
|
20
21
|
return lexProvider.sendMessage(botConfig, message);
|
|
21
22
|
};
|
package/src/lex-v2/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { onComplete, send } from './apis';
|
|
5
5
|
import { IInteractions } from './types/AWSLexV2ProviderOption';
|
|
6
6
|
|
|
7
7
|
export const Interactions: IInteractions = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { OnCompleteInput, SendInput } from './inputs';
|
|
5
5
|
import { SendOutput } from './outputs';
|
|
6
6
|
|
|
7
7
|
export interface AWSLexV2ProviderOption {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { AWSLexV2ProviderOption } from '../types';
|
|
5
4
|
import { Amplify } from '@aws-amplify/core';
|
|
6
5
|
|
|
6
|
+
import { AWSLexV2ProviderOption } from '../types';
|
|
7
|
+
|
|
7
8
|
export const resolveBotConfig = (
|
|
8
9
|
botName: string,
|
|
9
10
|
): AWSLexV2ProviderOption | undefined => {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export interface InteractionsTextMessage {
|
|
5
5
|
content: string;
|
|
6
6
|
options: {
|
|
7
7
|
messageType: 'text';
|
|
8
8
|
};
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
|
|
11
|
-
export
|
|
11
|
+
export interface InteractionsVoiceMessage {
|
|
12
12
|
content: object;
|
|
13
13
|
options: {
|
|
14
14
|
messageType: 'voice';
|
|
15
15
|
};
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
17
|
|
|
18
18
|
export type InteractionsMessage =
|
|
19
19
|
| InteractionsTextMessage
|
|
@@ -24,6 +24,4 @@ export type InteractionsOnCompleteCallback = (
|
|
|
24
24
|
completion?: InteractionsResponse,
|
|
25
25
|
) => void;
|
|
26
26
|
|
|
27
|
-
export type InteractionsResponse =
|
|
28
|
-
[key: string]: any;
|
|
29
|
-
};
|
|
27
|
+
export type InteractionsResponse = Record<string, any>;
|
package/src/types/inputs.ts
CHANGED
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
InteractionsOnCompleteCallback,
|
|
7
7
|
} from './Interactions';
|
|
8
8
|
|
|
9
|
-
export
|
|
9
|
+
export interface InteractionsSendInput {
|
|
10
10
|
botName: string;
|
|
11
11
|
message: string | InteractionsMessage;
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
13
|
|
|
14
|
-
export
|
|
14
|
+
export interface InteractionsOnCompleteInput {
|
|
15
15
|
botName: string;
|
|
16
16
|
callback: InteractionsOnCompleteCallback;
|
|
17
|
-
}
|
|
17
|
+
}
|
package/src/utils/commonUtils.ts
CHANGED
|
@@ -12,6 +12,8 @@ export const unGzipBase64AsJson = async (gzipBase64: string | undefined) => {
|
|
|
12
12
|
|
|
13
13
|
return JSON.parse(objString);
|
|
14
14
|
} catch (error) {
|
|
15
|
-
return Promise.reject(
|
|
15
|
+
return Promise.reject(
|
|
16
|
+
new Error('unable to decode and decompress ' + error),
|
|
17
|
+
);
|
|
16
18
|
}
|
|
17
19
|
};
|
|
@@ -6,10 +6,10 @@ import { ungzip } from 'pako';
|
|
|
6
6
|
|
|
7
7
|
export const convert = async (stream: object): Promise<Uint8Array> => {
|
|
8
8
|
if (!(stream instanceof Blob)) {
|
|
9
|
-
return Promise.reject('Invalid content type');
|
|
9
|
+
return Promise.reject(new Error('Invalid content type'));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
return new Promise(
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
13
|
try {
|
|
14
14
|
const fileReaderInstance = new FileReader();
|
|
15
15
|
fileReaderInstance.readAsDataURL(stream);
|
|
@@ -22,13 +22,14 @@ export const convert = async (stream: object): Promise<Uint8Array> => {
|
|
|
22
22
|
resolve(decodedArrayBuffer);
|
|
23
23
|
};
|
|
24
24
|
} catch (error) {
|
|
25
|
-
reject('unable to convert blob to arrayBuffer: ' + error);
|
|
25
|
+
reject(new Error('unable to convert blob to arrayBuffer: ' + error));
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
export const base64ToArrayBuffer = (base64: string): Uint8Array => {
|
|
31
31
|
const binaryString: string = decode(base64);
|
|
32
|
+
|
|
32
33
|
return Uint8Array.from(binaryString, c => c.charCodeAt(0));
|
|
33
34
|
};
|
|
34
35
|
|
|
@@ -40,7 +41,7 @@ export const gzipDecompressToString = async (
|
|
|
40
41
|
const result: string = ungzip(data, { to: 'string' });
|
|
41
42
|
resolve(result);
|
|
42
43
|
} catch (error) {
|
|
43
|
-
reject('unable to decompress' + error);
|
|
44
|
+
reject(new Error('unable to decompress' + error));
|
|
44
45
|
}
|
|
45
46
|
});
|
|
46
47
|
};
|
package/src/utils/utils.ts
CHANGED
|
@@ -9,7 +9,7 @@ export const convert = async (stream: object): Promise<Uint8Array> => {
|
|
|
9
9
|
.arrayBuffer()
|
|
10
10
|
.then(buffer => new Uint8Array(buffer));
|
|
11
11
|
} else {
|
|
12
|
-
return Promise.reject('Invalid content type');
|
|
12
|
+
return Promise.reject(new Error('Invalid content type'));
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
|
|
@@ -20,7 +20,7 @@ export const base64ToArrayBuffer = (base64: string): Uint8Array => {
|
|
|
20
20
|
export const gzipDecompressToString = async (
|
|
21
21
|
data: Uint8Array,
|
|
22
22
|
): Promise<string> => {
|
|
23
|
-
return
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
24
|
gunzip(data, (err, resp) => {
|
|
25
25
|
if (err) reject(err);
|
|
26
26
|
else resolve(strFromU8(resp));
|