Zahra Amin Zahra Amin -3 years ago 135
Android Question

Amazon Lex Bot only works in Speech to Speech Demo in Sample App Made with AWS Mobile Hub

I made a project in AWS Mobile Hub and am trying to deploy a Lex conversational bot into the app. I am using Android Studio. I am having an issue with one of the bots. This bot is a simple FAQ chat bot that uses Lambda code hook fulfillment to post answers to user questions.

The bot works perfectly in the Lex console as well as on a Slack channel. However in the sample app it only works in the voice to voice demo. When I try the text to text demo the bot never responds to user inputs and often the app crashes.

I downloaded and tested several sample apps with different bots integrated. All the bots that don't have lambda code hooks work perfectly in both the text and speech demos. However the bots that have lambda code hooks only work in the speech demo.

Edit: I tried again and found that bots w/ lambda code hooks do respond, but only if the response is delegated to Lex and comes from configurations set in the console or if the responses comes from a Lambda input validation code hook. It doesn't respond when the response is expected to come from a Lambda fulfillment code hook (using PostContent runtime API operation).

I thought maybe I wrote my Lambda function wrong so I also tested using the sample OrderFlowers bot and its sample code hook and got the same result.

Note the Lambda functions are not throwing invocation errors, all of the invocations are being handled successfully but the response doesn't appear.

Any ideas on how I can successfully get a text fulfillment response working?

Answer Source

Try updating promptUserToRespond in to the following:

public void promptUserToRespond(Response response, LexServiceContinuation continuation) {

    if(!DialogState.ReadyForFulfillment.toString().equals(response.getDialogState()) && !DialogState.Fulfilled.toString().equals(response.getDialogState())) {
        addMessage(new TextMessage(response.getTextResponse(), "rx", getCurrentTimeStamp()));

    else if(DialogState.Fulfilled.toString().equals(response.getDialogState())) {
        addMessage(new TextMessage(response.getTextResponse(), "rx", getCurrentTimeStamp()));

        inConversation = false;

The crash was probably because inConversation was not set to false and this method was not printing anything out for the "Fulfilled" state. We are discussing a better way to do this in the SDK but this should work for now.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download