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