@@ -73,11 +73,12 @@ import MinButton from '@/components/MinButton';
7373import ToolbarContainer from ' @/components/ToolbarContainer' ;
7474import MessageList from ' @/components/MessageList' ;
7575import InputContainer from ' @/components/InputContainer' ;
76- import LexRuntime from ' aws-sdk/clients/lexruntime' ;
77- import LexRuntimeV2 from ' aws-sdk/clients/lexruntimev2' ;
76+ // import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers';
77+ import { LexRuntimeServiceClient } from ' @aws-sdk/client-lex-runtime-service' ;
78+ import { LexRuntimeV2Client } from ' @aws-sdk/client-lex-runtime-v2' ;
79+ import { PollyClient } from ' @aws-sdk/client-polly' ;
80+
7881
79- import { Config as AWSConfig , CognitoIdentityCredentials }
80- from ' aws-sdk/global' ;
8182
8283export default {
8384 name: ' lex-web' ,
@@ -156,7 +157,7 @@ export default {
156157 if (! this .isMobile ) {
157158 document .documentElement .style .overflowY = ' hidden' ;
158159 }
159-
160+
160161 this .initConfig ()
161162 .then (() => Promise .all ([
162163 this .$store .dispatch (
@@ -191,44 +192,25 @@ export default {
191192 if (! poolId) {
192193 return Promise .reject (new Error (' no cognito.poolId found in config' ))
193194 }
195+
194196
195- const AWSConfigConstructor = (window .AWS && window .AWS .Config ) ?
196- window .AWS .Config :
197- AWSConfig;
198-
199- const CognitoConstructor =
200- (window .AWS && window .AWS .CognitoIdentityCredentials ) ?
201- window .AWS .CognitoIdentityCredentials :
202- CognitoIdentityCredentials;
203-
204- const LexRuntimeConstructor = (window .AWS && window .AWS .LexRuntime ) ?
205- window .AWS .LexRuntime :
206- LexRuntime;
207-
208- const LexRuntimeConstructorV2 = (window .AWS && window .AWS .LexRuntimeV2 ) ?
209- window .AWS .LexRuntimeV2 :
210- LexRuntimeV2;
211-
212- const credentials = new CognitoConstructor (
213- { IdentityPoolId: poolId },
214- { region: region },
215- );
216-
217- const awsConfig = new AWSConfigConstructor ({
197+ const awsConfig = {
218198 region: region,
219- credentials,
220- }) ;
199+ credentials: this . $lexWebUi . awsConfig . credentials ,
200+ };
221201
222- this .$lexWebUi .lexRuntimeClient = new LexRuntimeConstructor (awsConfig);
223- this .$lexWebUi .lexRuntimeV2Client = new LexRuntimeConstructorV2 (awsConfig);
202+ this .$lexWebUi .lexRuntimeClient = new LexRuntimeServiceClient (awsConfig);
203+ this .$lexWebUi .lexRuntimeV2Client = new LexRuntimeV2Client (awsConfig);
204+ this .$lexWebUi .pollyClient = new PollyClient (awsConfig)
224205 /* eslint-disable no-console */
225- console .log (` lexRuntimeV2Client : ${ JSON .stringify (this .$lexWebUi .lexRuntimeV2Client )} ` );
206+ // console.log('this.$store.state', this.$store.state);
207+ // console.log(`lexRuntimeV2Client : ${JSON.stringify(this.$lexWebUi.lexRuntimeV2Client)}`);
226208
227209 const promises = [
228210 this .$store .dispatch (' initMessageList' ),
229- this .$store .dispatch (' initPollyClient' , this .$lexWebUi .pollyClient ),
211+ this .$store .dispatch (' initPollyClient' , this .$lexWebUi .pollyClient , this . $lexWebUi . awsConfig . credentials ),
230212 this .$store .dispatch (' initLexClient' , {
231- v1client: this .$lexWebUi .lexRuntimeClient , v2client: this .$lexWebUi .lexRuntimeV2Client ,
213+ v1client: this .$lexWebUi .lexRuntimeClient , v2client: this .$lexWebUi .lexRuntimeV2Client , credentials : this . $lexWebUi . awsConfig . credentials
232214 }),
233215 ];
234216 console .info (' CONFIG : ' , this .$store .state .config );
@@ -589,4 +571,4 @@ NOTE: not using var() for different heights due to IE11 compatibility
589571
590572html { font-size : 14px !important ; }
591573
592- </style >
574+ </style >
0 commit comments