LexSlu Plugin: Expose LexRuntimeV2ClientConfig as libraryConfig and make it optional
rmtuckerphx opened this issue · 0 comments
rmtuckerphx commented
I'm submitting a...
- Bug report
- Feature request
- Documentation issue or request
- Other... Please describe:
Expected Behavior
Allow plugin to not explicitly set credentials and region.
Current Behavior
The existing slu-lex implementation requires credentials with accessKeyId and secretAccessKey. These aren't required if the code is run in Lambda or Kubernetes and a role is assigned externally.
Error Log
If you have an error log, please paste it here.
None
Your Environment
- Jovo Framework version used: 4.5.6
- Operating System: Windows 11
Code Sample
Here is some code to review of how the plugin could be changed and remain backward compatible:
export interface LexSluConfig extends InterpretationPluginConfig {
bot: {
id: string;
aliasId: string;
};
credentials?: AwsCredentialIdentity; // @deprecated use libraryConfig
region?: string; // @deprecated use libraryConfig
locale?: string;
localeMap?: Record<string, string>;
fallbackLocale: string;
asr: boolean;
nlu: boolean;
libraryConfig?: LexRuntimeV2ClientConfig; // new
}
export type LexSluInitConfig = DeepPartial<LexSluConfig> & Pick<LexSluConfig, 'bot'>;
export class LexSlu extends SluPlugin<LexSluConfig> {
// ...
constructor(config: LexSluInitConfig) {
super(config);
const clientConfig = this.config?.libraryConfig || {};
if (this.config.credentials) {
clientConfig.credentials = this.config.credentials;
}
if (this.config.region) {
clientConfig.region = this.config.region;
}
this.client = new LexRuntimeV2Client(clientConfig);
}
getDefaultConfig(): LexSluConfig {
return {
...super.getDefaultConfig(),
bot: { id: '', aliasId: '' },
fallbackLocale: 'en_US',
asr: true,
nlu: true,
};
}
getInitConfig(): RequiredOnlyWhere<LexSluConfig, 'bot'> {
return {
bot: { id: '', aliasId: '' },
};
}
// ...
}