Closed kshitijgodara closed 1 year ago
Hi @kshitijgodara thanks for raising this issue. I have not been able to reproduce your error yet, but I did try to go through the V2 flow and noticed that our documentation is lacking some necessary steps to get this running. Part of what is missing is the response no longer sends back a message
property but rather an array of messages
objects that you can access like console.log(response.messages)
Regardless, your error seems more like there is some is configured incorrectly. I do not see anything from the code you have provided but could you list how you are configuring Amplify after you define the config? Mine is set as Amplify.configure(interactionsConfig)
The only other thing I saw that was different was how you listed localeId
in the config. I have it working with localeId: "en_US"
rather than "en-US"
.
One thing I noticed that might be unrelated is that you have aws-amplify-react-native
and @aws-amplify/ui-react
both installed. Just so you know we now have a new UI package for react-native that is in dev preview
Yes correct. It is supposed to be en-US. But issue is not because of this.
import 'react-native-get-random-values';
import 'react-native-url-polyfill/auto';
import React from 'react';
import AppNavigator from './src/navigation/appNavigator';
import {Provider} from 'react-redux';
import store from './src/store';
import {Amplify} from 'aws-amplify';
import {AWSLexV2Provider} from '@aws-amplify/interactions';
Amplify.addPluggable(new AWSLexV2Provider());
const interactionsConfig = {
Auth: {
identityPoolId: 'us-east-1:XYZ',
region: 'us-east-1',
},
Interactions: {
bots: {
Reema: {
name: 'Reema',
aliasId: 'XYZ',
botId: 'XYZ',
localeId: 'en_US',
region: 'us-east-1',
providerName: 'AWSLexV2Provider',
},
},
},
};
Amplify.configure(interactionsConfig);
const App = () => {
return (
<Provider store={store}>
<AppNavigator />
</Provider>
);
};
export default App;
So for me this was not working. But after trying lot of things. I tried this on my entry screen say splash -
const provider = new AWSLexV2Provider();
Interactions.addPluggable(provider);
Things started working fine.
But question remains same, why do we have to plug again ? And not sure documents are helpful or not
You shouldn't have to addPluggable
twice, but are you saying that original code was in App.tsx instead of index.js?
If so that could be a problem but I'm not 100% sure on that. We do however recommend that you configure your app at the root or entry point of your project which should be index.js
for a React Native project built with their CLI.
This may be good feedback for our docs if that was the only issue, can you try moving all of the following into index.js
instead of App.js/tsx
:
import 'react-native-get-random-values';
import 'react-native-url-polyfill/auto';
import {Amplify} from 'aws-amplify';
import {AWSLexV2Provider} from '@aws-amplify/interactions';
Amplify.addPluggable(new AWSLexV2Provider());
const interactionsConfig = {
Auth: {
identityPoolId: 'us-east-1:XYZ',
region: 'us-east-1',
},
Interactions: {
bots: {
Reema: {
name: 'Reema',
aliasId: 'XYZ',
botId: 'XYZ',
localeId: 'en_US',
region: 'us-east-1',
providerName: 'AWSLexV2Provider',
},
},
},
};
Amplify.configure(interactionsConfig);
I did tried as you said to move to index.js but same thing. Still error is same as -
WARN Possible Unhandled Promise Rejection (id: 0): "Bot AWSLexV2Provider does not have valid pluggin did you try addPluggable first?" LOG finish {"utteranceId": 105553147102464}
Would you be able to provide a sample repo showing this behavior so that I can see the error? I have not been able to reproduce on my own and don't see anything wrong with the code you are now using.
@kshitijgodara can you try importing and logging Interactions before calling addPluggable?
Now your index.js would be like:
import 'react-native-get-random-values';
import 'react-native-url-polyfill/auto';
import {Amplify, Interactions} from 'aws-amplify';
import {AWSLexV2Provider} from '@aws-amplify/interactions';
console.log(!!Interactions);
Amplify.addPluggable(new AWSLexV2Provider());
const interactionsConfig = {
Auth: {
identityPoolId: 'us-east-1:XYZ',
region: 'us-east-1',
},
Interactions: {
bots: {
Reema: {
name: 'Reema',
aliasId: 'XYZ',
botId: 'XYZ',
localeId: 'en_US',
region: 'us-east-1',
providerName: 'AWSLexV2Provider',
},
},
},
};
Amplify.configure(interactionsConfig);
@kshitijgodara, did you get a chance to try the recommendations above? Want to circle back and see if you're still experiencing this issue.
Hello again, @kshitijgodara. Wanted to provide some additional feedback after doing another review of this issue. In previous comments, you had mentioned that adding the Lex V2 pluggable Interactions.addPluggable(provider);
to your splash screen actually works. If that's the case, it's possible this is an issue with the order of operations:
await Interactions.send('BookTrip', userInput);
gets called firstAmplify.addPluggable(new AWSLexV2Provider());
is called afterBut the proper sequence should be the following:
import {Amplify} from 'aws-amplify';
import {AWSLexV2Provider} from '@aws-amplify/interactions';
Amplify.addPluggable(new AWSLexV2Provider());
const interactionsConfig = { Auth: { identityPoolId: 'us-east-1:XYZ', region: 'us-east-1', }, Interactions: { bots: { Reema: { name: 'Reema', aliasId: 'XYZ', botId: 'XYZ', localeId: 'en_US', region: 'us-east-1', providerName: 'AWSLexV2Provider', }, }, }, }; Amplify.configure(interactionsConfig);
2. The `send` call should be made after the above, such as:
`const response = await Interactions.send('BookTrip', userInput);`
For some additional context, the Interactions category supports Lex V1 by default and adding a pluggable is **_NOT_** required. However, Lex V2 is exposed as a pluggable and you would have to add the pluggable in order to access the API's it provides.
**TLDR - This issue appears to be related to the "order of operations" and how there's default support for Lex V1 out of the box (and why it's working), but Lex V2 requires a pluggable before API's can be used.**
Hopefully this clears everything up for you and anyone else that comes across similar issues regarding Lex V2 and Amplify's Interactions category. I'll close out the issue at this point, but feel free to comment back with any further problems you experience. We appreciate you opening this issue!
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Interactions
Amplify Categories
interactions
Environment information
Describe the bug
I am trying to use Amazon Lex2 for my app. I am able to integrate LexV1 successfully but Lex2 is giving me error for pluggable.
On Calling Lex 2 Bot, I am getting this error -
How I am calling Bot -
I am able to call Lex 1 bot from above code very easily.
Expected behavior
It should work as expected.
Reproduction steps
I have followed same steps -
https://docs.amplify.aws/lib/interactions/getting-started/q/platform/react-native/#lex-v2-bot
Just with manual config.
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
Log Error
Lex 2 Console -
Lex 1 Console